jquery-datatables-checkboxes
jquery-datatables-checkboxes copied to clipboard
Select checkboxes on page load - server-side
Is there a way to set selected checkboxes server-side?
I did this:
var initialList = ['2847', '3341'];
'createdCell': function (td, cellData, rowData, rowIndex, colIndex) { if ((initialList.indexOf(rowData[0]) !== -1)) { this.api().cell(td).checkboxes.select(); } }
But this code just select when i enter on checkboxes page.
If the checkboxes to be selected is on 2nd page, datatable will show 0 selected rows, and when i navigate to 2nd page, it shows me 1 row selected.
There is a way to fix this?
I also tried table.column(0).checkboxes.select() but it select all rows.
Hi @mpryvkin
I don't suppose there has been any updates to this question? Trying to see if there are any ways to select a checkbox on another page that has yet to be loaded server-side. If a user clicks to that page, it should already have the checkbox selected based on an array of IDs I have specified.
I've made code changes to allow for the prepopulation of certain rows on initialization. Works with server side pagination, which is my use-case. https://github.com/gyrocode/jquery-datatables-checkboxes/pull/144
Edit: here is an example usage. Say you have a table of data. The first column is an ID, which becomes the checkbox, and subsequently the value that is saved when selected. Let's say you want to preselect IDs 34 and 35.
$('#example').DataTable({
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true,
'initialSelectionArray': [ '34', '35' ] // This is the new line
}
}
],
'select': {
'style': 'multi'
},
'order': [[1, 'asc']],
'processing': true,
'serverSide': true,
'ajax': '/path/to/data',
});