Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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