Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox sort in DataTables using jQuery

I've been trying to sort a checkbox field in DataTables jQuery plugin to check and uncheck.

I'm creating the input (checkbox) inside the table like this:

'<input type="checkbox" '+ check +' />'

check is containing the text "checked" or "".

So far I tried just to add DOM checkbox type of sort, like this:

{ "sSortDataType": "dom-checkbox" }

When I use the entire code from the plugin's API documentation, I get the following error:

Uncaught TypeError: Cannot read property 'afnSortData' of undefined inside my console.


Problem: pressing on the column header won't sort the column by checked or unchecked checkboxes.

I would like to get suggestions how to fix the above mentioned error or another way to sort using only jQuery and plugin's methods.

Thanks.


EDIT

Just tried with a fixed code - no error. But sorting is messed up: it's just replacing with each other but not sorting. For example: if I have 1 checkbox checked and 9 not, the checked checkbox is switching from the third place to the sixth and again to the third and so on.

like image 429
Vera Gavriel Avatar asked Apr 04 '13 23:04

Vera Gavriel


1 Answers

what i did is creatinga bool var in hidden P so it will be in the sameplace as the checkbox.than i disabled the option of change value in checkbox and the sorting is now working.

like image 79
Vera Gavriel Avatar answered Sep 20 '22 01:09

Vera Gavriel