|
| 1 | +<article class="main-content"> |
| 2 | + <header class="article-header"> |
| 3 | + <h1><i class="fa fa-play"></i> Disabling deep watchers</h1> |
| 4 | + </header> |
| 5 | + <section class="article-content"> |
| 6 | + <p> |
| 7 | + The <code>angular-datatables</code> uses deep search for changes on every <code>$digest</code> cycle. |
| 8 | + Meaning every time any Angular event happens (ng-clicks, etc.), the entire array, each of it's children, it's children's children, and so forth gets compared to a cached copy. |
| 9 | + </p> |
| 10 | + <p> |
| 11 | + There is an attribute to add so that if the directive has a truthy value for <code>dt-disable-deep-watchers</code> at compile time then it will use <code>$watchCollection(...)</code> instead. |
| 12 | + This would allow users to prevent big datasets from thrashing Angular's <code>$digest</code> cycle at their own discretion |
| 13 | + </p> |
| 14 | + </section> |
| 15 | + <section class="showcase" ng-controller="withAjaxCtrl"> |
| 16 | + <tabset> |
| 17 | + <tab heading="Preview"> |
| 18 | + <article class="preview"> |
| 19 | + <div> |
| 20 | + <table datatable dt-options="dtOptions" dt-columns="dtColumns" dt-disable-deep-watchers="true" class="row-border hover"></table> |
| 21 | + </div> |
| 22 | + </article> |
| 23 | + </tab> |
| 24 | + <tab heading="HTML"> |
| 25 | +<div hljs> |
| 26 | +<div ng-controller="withAjaxCtrl"> |
| 27 | + <table datatable dt-options="dtOptions" dt-columns="dtColumns" dt-disable-deep-watchers="true" class="row-border hover"></table> |
| 28 | +</div> |
| 29 | +</div> |
| 30 | + </tab> |
| 31 | + <tab heading="JS"> |
| 32 | +<div hljs language="js"> |
| 33 | +angular.module('datatablesSampleApp', ['datatables']).controller('withAjaxCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder) { |
| 34 | + $scope.dtOptions = DTOptionsBuilder.fromSource('data.json') |
| 35 | + .withPaginationType('full_numbers'); |
| 36 | + $scope.dtColumns = [ |
| 37 | + DTColumnBuilder.newColumn('id').withTitle('ID'), |
| 38 | + DTColumnBuilder.newColumn('firstName').withTitle('First name'), |
| 39 | + DTColumnBuilder.newColumn('lastName').withTitle('Last name').notVisible() |
| 40 | + ]; |
| 41 | +}); |
| 42 | +</div> |
| 43 | + </tab> |
| 44 | + <tab heading="Example data"> |
| 45 | + <p class="example-data"> |
| 46 | + <a target="_blank" href="/angular-datatables/data.json" tooltip="data.json">data.json <i class="fa fa-external-link"></i></a> |
| 47 | + </p> |
| 48 | +<div hljs language="json"> |
| 49 | +[{ |
| 50 | + "id": 860, |
| 51 | + "firstName": "Superman", |
| 52 | + "lastName": "Yoda" |
| 53 | +}, { |
| 54 | + "id": 870, |
| 55 | + "firstName": "Foo", |
| 56 | + "lastName": "Whateveryournameis" |
| 57 | +}, { |
| 58 | + "id": 590, |
| 59 | + "firstName": "Toto", |
| 60 | + "lastName": "Titi" |
| 61 | +}, { |
| 62 | + "id": 803, |
| 63 | + "firstName": "Luke", |
| 64 | + "lastName": "Kyle" |
| 65 | +}, |
| 66 | +... |
| 67 | +] |
| 68 | +</div> |
| 69 | + </tab> |
| 70 | + </tabset> |
| 71 | + </section> |
| 72 | +</article> |
0 commit comments