Sorting by a 'checked' column?
Sorting by a 'checked' column?
vsek
Posts: 30Questions: 17Answers: 0
Hello, I have a column that is a check box on column 0. So I did this code in hopes of sorting first by column zero(the checkbox) and column 2. It sorts fine by column 2 but never for the check box one. Is there a way to sort the way I want?
var standardDataTable = $(dataTableId).DataTable({
ajaxSource : "/cma/contents/screening/restrictedEntityGroupDetails_data?groupName=<%= (String)request.getAttribute("groupName")%>",
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf', 'searchBuilder'
],
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true
},
'createdCell': function (td, cellData, rowData, row, col){
if(rowData[0] === 'x')
{this.api().cell(td).checkboxes.select();}
}
}
],
'select': {
'style': 'single'
},
'order': [[0, 'asc'], [ 2, 'asc' ]]
});
This discussion has been closed.
Answers
You will need a value for the column to sort it. And the value will need to change based on the checkbox selection. See this Editor example. The value is either 1 or 0 depending on the checkbox state. Does your column 0 have a value. Can you provide a simple test case showing what you have so we can offer suggestions?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin