Filtering buttons
Filtering buttons
Chris230291
Posts: 34Questions: 10Answers: 1
in General
Hello. I am able to filter text boxes and check boxes using
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
return this.api().column(col, { order: 'index' }).nodes().map(function (td, i) {
return $('input', td).prop('checked') ? '1' : '0';
});
}
/* Create an array with the values of all the input boxes in a column */
$.fn.dataTable.ext.order['dom-text'] = function (settings, col) {
return this.api().column(col, { order: 'index' }).nodes().map(function (td, i) {
return $('input', td).val();
});
}
And
"columns": [
{ "width": "1%", "orderDataType": "dom-checkbox" },
{ "width": "20%" },
{ "width": "20%", "orderDataType": "dom-text", type: 'string' },
{ "width": "20%" },
{ "width": "20%", "orderDataType": "dom-text", type: 'string' },
{ "width": "1%" }
],
I tried using the same method for columns that contain buttons but it doesnt work.
Here is my buttons
<input type="button" class="myButton" value="{{ i['name'] }}" onclick="select(this)" data-link="{{ i['link'] }}">
Is it possible to search the value of them?
Thanks,
Chris
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thanks for the reply. Thats neat. Here is what I came up with http://live.datatables.net/husuwace/1/edit?html,js,output
You could do something like this: http://live.datatables.net/husuwace/3/edit
Colin
Sorry I'm not sure why it wasn't working before and no idea why I included that other javascript. I misunderstood the docs. It seems this is all I need to have sortable columns with buttons and text fields...
http://live.datatables.net/husuwace/5/edit?html,js,output
Actually I take that back. Those other scripts are needed else I cant use 'orderFixed'.
I'm getting muddled on what you're after. In the example I posted it was searching on the value of the button that was clicked. If that's not what you're after, can you expand more please, as that was what you asked for : "Is it possible to search the value of them?"
Colin
Sorry for my bad explanation.
What I wanted was to be able to sort columns that contain buttons with text by clicking on the column head. For whatever reason that wasn't working for me until now.
I thought the script I was adding above the main table script was required for column sorting to work on any columns that don't have regular text.
But it seems that is only sometimes required? if you look at the following example, all columns can be sorted. But take away the script above the main table script, and the checkbox column stops working.
http://live.datatables.net/husuwace/7/edit?html,js,output
Why does the checkbox column need the script but the others do not?
The others do need the script. Its ordering based on the original data. To see the problem change
Paris
toxParis
and you will see the order is now incorrect. Try the same with this updated example with thedom-text
plugin added:http://live.datatables.net/husuwace/8/edit
Kevin
Yes you are correct thank you. I wonder why checkboxes don't work at all without it though.
The plugin is returning this:
If the checkbox is checked its returning
1
else0
. The sorting is taking place on the 1 or 0 not the checkbox.Kevin
OK thanks