Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Improve Angular digest performance by watching dtOptions more shallowly #144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dist/angular-datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
compile: function (tElm) {
var _staticHTML = tElm[0].innerHTML;
return function postLink($scope, $elem, iAttrs, ctrl) {
$scope.$watch('[dtOptions, dtColumns, dtColumnDefs]', function (newVal, oldVal) {
function handleChanges(newVal, oldVal) {
if (newVal !== oldVal) {
var newDTOptions = newVal[0], oldDTOptions = oldVal[0];
// Do not rerender if we want to reload. There are already
Expand All @@ -388,7 +388,17 @@
newDTOptions.reload = false;
}
}
}, true);
}
// Options can hold heavy data, and other deep/large objects.
// watchcollection can improve this by only watching shallowly
var watchFunction = iAttrs.disableDeepWatchers ? '$watchCollection' : '$watch';
angular.forEach([
'dtColumns',
'dtColumnDefs',
'dtOptions'
], function (tableDefField) {
$scope[watchFunction].call($scope, tableDefField, handleChanges, true);
});
ctrl.showLoading($elem);
ctrl.render($elem, ctrl.buildOptionsPromise(), _staticHTML);
};
Expand Down
Loading