Skip to content

Commit

Permalink
Add DTDefaultOptions.setOption #796
Browse files Browse the repository at this point in the history
  • Loading branch information
l-lin committed Sep 2, 2016
1 parent b4f7e0e commit b65cea0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
6 changes: 4 additions & 2 deletions demo/advanced/angularWayDataChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ angular.module('showcase.angularWay.dataChange', ['datatables', 'ngResource'])

function AngularWayChangeDataCtrl($resource, DTOptionsBuilder, DTColumnDefBuilder) {
var vm = this;
vm.persons = $resource('data1.json').query();
vm.dtOptions = DTOptionsBuilder.newOptions().withPaginationType('full_numbers');
vm.persons = $resource('data.json').query();
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption("order", [[1, "asc"]])
.withPaginationType('full_numbers');
vm.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0),
DTColumnDefBuilder.newColumnDef(1),
Expand Down
12 changes: 12 additions & 0 deletions demo/api/apiDefaultOptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,17 @@ <h3><code>DTDefaultOptions</code></h3>
</div>
</td>
</tr>
<tr>
<td><code>DTDefaultoptions</code></td>
<td><code>setOption(key, value)</code></td>
<td>
Set a default option for all DataTables.
<div hljs language="js">
angular.module('myModule', ['datatables']).run(function(DTDefaultOptions) {
DTDefaultOptions.setOption('dom', 'lpfrtip');
});
</div>
</td>
</tr>
</tbody>
</table>
16 changes: 15 additions & 1 deletion dist/angular-datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
setLanguage: setLanguage,
setDisplayLength: setDisplayLength,
setBootstrapOptions: setBootstrapOptions,
setDOM: setDOM
setDOM: setDOM,
setOption: setOption
};

return options;
Expand Down Expand Up @@ -693,6 +694,19 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
});
return options;
}

/**
* Set global default option to all DataTables.
* @param key the key of the default option
* @param value the value of the default option
*/
function setOption(key, value) {
if (angular.isString(key)) {
var obj = {};
obj[key] = value;
$.extend($.fn.DataTable.defaults, obj);
}
}
}

'use strict';
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-datatables.min.js

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion src/angular-datatables.options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function dtDefaultOptions() {
setLanguage: setLanguage,
setDisplayLength: setDisplayLength,
setBootstrapOptions: setBootstrapOptions,
setDOM: setDOM
setDOM: setDOM,
setOption: setOption
};

return options;
Expand Down Expand Up @@ -101,4 +102,17 @@ function dtDefaultOptions() {
});
return options;
}

/**
* Set global default option to all DataTables.
* @param key the key of the default option
* @param value the value of the default option
*/
function setOption(key, value) {
if (angular.isString(key)) {
var obj = {};
obj[key] = value;
$.extend($.fn.DataTable.defaults, obj);
}
}
}

0 comments on commit b65cea0

Please sign in to comment.