Sort columns by inserted values and checked checkboxes?
Sort columns by inserted values and checked checkboxes?
Hi! There is my example:
http://live.datatables.net/xupenosa/1/edit?html,css,js,output
Problem is:
There is an script, which is counting checked checkboxes per row and incrementing/decrementing value into "Rate" column. Numbers in this columns wont sort, I dont know why..
Also I want to sort columns by checked checkboxes, for example: I've checked 2 checkboxes in first column (upper and lower row), When I click thead, I want to get these rows with checked ones on top.
Is there any way to fix these things?
Answers
You need to let DataTables know that you have updated the data with
row().invalidate()
or similarinvalidate()
methods to fix sorting for the last column.To enable sorting by state of checkboxes, use search plug-in code from Live DOM ordering.
For example:
See updated example for code and demonstration.
See more articles about jQuery DataTables on gyrocode.com.
Thank you for discussing this example. My datatables table now sorts correctly, however, I do not understand lines 19 through 26 shown above. In order to better understand how it works, I tried to add console.log notes, but these are never shown. How can I get console.log to show up in my console log?
I need to add another step to the function in that I want to change the content of another column based on whether the checkbox is checked.
Perhaps your console logging has been disabled or filtered out in your browser? Certainly DataTables doesn't do anything that would stop a
console.log()
message showing up.The
change
that is added above basically just callsrow().invalidate()
to make sure that DataTables is up to date with the latest data.Allan