mirror of
https://github.com/DataTables/DataTables.git
synced 2024-12-01 13:24:10 +01:00
b2de50229e
- As part of completing the planning development for reading data, I've added support for calling functions from the string defined in `data` and `render` column options. So you can now do something like: `render: 'name()'` rather than needing to use an anon function and calling name() in that. This is useful for cases where you want to give DataTables an array of Javascript instances, rather than objects or arrays (see example below). It also fully supports the continuation of the dotted notation DataTables supports, so you could use `name().first` if `name()` returns an object. Again to make it easier than needed to define a function. - Documentation for `data` and `render` updated to reflect this abilities - Unit tests for this still to come - There is one backwards incompatiblity that should be noted - although I think this is a real edge case and I just can't see it being an issue. If before, you had `data:null` without `render` or `defaultContent` specified, DataTables would have output an empty cell. Now it will output the original data source object. Can't see this being an issue since, why would you have a column empty cells? If this is an issue, then you simply need to add `defaultContent:''` now. - Example use case, using Javascript instances: $(document).ready(function() { var z = function (i) { this.a = function (set) { if ( set ) { return this; } return i+'-0'; }; this.b = function (set) { if ( set ) { return this; } return i+'-1'; }; this.c = function (set) { if ( set ) { return this; } return i+'-2'; }; this.d = function (set) { if ( set ) { return this; } return i+'-3'; }; this.e = function (set) { if ( set ) { return this; } return { q: i+'-4q', w: i+'-4w' }; }; }; window.dataset = [ new z(0), new z(1), new z(2), new z(3), new z(4), new z(5) ]; $('#example').dataTable( { columns: [ { data: null, /*render: 'a()'*/ }, { data: 'b()' }, { data: 'c' }, { data: 'd()' }, { data: 'e().q' } ], data: dataset } ); } ); |
||
---|---|---|
.. | ||
css | ||
images | ||
js | ||
src | ||
unit_testing |