javascript - Unable to select rows programatically in drawCallback() of DataTables -
i using latest datatables select extension. trying select multiple rows programatically after table rendered. trying achieve in drawcallback() below:
var table = $('#example').datatable({ "select": { "style": 'multi' }, "columns": [ { "data": "name" }, { "data": "position" }, { "data": "office" }, { "data": "age" }, { "data": "start_date" }, { "data": "salary" } ], "rowid": "name", "drawcallback": function( settings ) { var api = new $.fn.datatable.api( settings ); api.rows(["[id='bradley greer']", "[id='ashton cox']"]).select(); } });
but, getting uncaught typeerror: cannot read property 'style' of undefined
error.
here link live version - http://live.datatables.net/yemiqafu/2/
p.s: have used [id='bradley greer']
selector since there space in id. had live demo , not reason error thrown.
solution
option drawcallback
not correct place perform row selection.
ideally, should use initcomplete
option instead, there issue select extension fixed 10/7/15 prevented select work in initcomplete
. until can use workaround below html sourced data or use nightly build of datatables , select extension.
for table data html source can select rows after datatables initialization.
var table = $('#example').datatable({ "select": { "style": 'multi' }, "columns": [ { "data": "name" }, { "data": "position" }, { "data": "office" }, { "data": "age" }, { "data": "start_date" }, { "data": "salary" } ], "rowid": "name" }); table.rows(["[id='bradley greer']", "[id='ashton cox']"]).select();
demo
see this example code , demonstration of workaround table html sourced data.
see this example code , demonstration of using nightly js/css builds table ajax sourced data. example used html sourced data well.
Comments
Post a Comment