Problems sorting by mRender-ed checkbox column
Problems sorting by mRender-ed checkbox column
Thanks so much for making this plugin. It really is great!
I'm pulling my hair out over one last issue... I've got a table that populates its data through ajax, and I have a column that uses mRender to convert the ajax data pulled in to a checkbox.
[code]
"mRender": function ( data, type, full ) {
if (data == "1") {
return '';
} else {
return '';
}
}
[/code]
I also set up a custom live sort function like you have on this page:
http://datatables.net/examples/plug-ins/dom_sort.html
Here it is (with a console.log outputting the results):
[code]
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
console.log(
$.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
});
);
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
});
}
[/code]
But it seems like using both mRender and the custom afnSortData functions together results in the sorting not working.
I've determined that if I remove the mRender and just populate my table by hand in the html, the sorting will work just fine.
Here's the debug output for this page:
http://debug.datatables.net/inaguv
The only thing I can see in the debug that's strange is under Tables > Full Table State > aoData > "_aSortData". It looks like the sort data isn't being properly inserted into that object. On an example page where the sorting works correctly, that object is populated with a 1 or 0 according to the state of the checkbox. But on the page with mRender functioning, it's populated with nothing.
Any idea why it wouldn't be passing that info?
Thanks,
Ryan
I'm pulling my hair out over one last issue... I've got a table that populates its data through ajax, and I have a column that uses mRender to convert the ajax data pulled in to a checkbox.
[code]
"mRender": function ( data, type, full ) {
if (data == "1") {
return '';
} else {
return '';
}
}
[/code]
I also set up a custom live sort function like you have on this page:
http://datatables.net/examples/plug-ins/dom_sort.html
Here it is (with a console.log outputting the results):
[code]
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
{
console.log(
$.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
});
);
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
});
}
[/code]
But it seems like using both mRender and the custom afnSortData functions together results in the sorting not working.
I've determined that if I remove the mRender and just populate my table by hand in the html, the sorting will work just fine.
Here's the debug output for this page:
http://debug.datatables.net/inaguv
The only thing I can see in the debug that's strange is under Tables > Full Table State > aoData > "_aSortData". It looks like the sort data isn't being properly inserted into that object. On an example page where the sorting works correctly, that object is populated with a 1 or 0 according to the state of the checkbox. But on the page with mRender functioning, it's populated with nothing.
Any idea why it wouldn't be passing that info?
Thanks,
Ryan
This discussion has been closed.
Replies
However, I see the issue. The good news is that this has been fixed in 1.10-dev: http://live.datatables.net/akavuc/edit#javascript,html . The bad news is that the DOM sorting functions will need to be updated since the private API that they used before has been removed in 1.10... It was poor of me using a private API before, but this is fixed in the DOM sorting functions in the example I linked to.
1.10 is pre-beta (although not by much) and can be downloaded as the nightly from http://datatables.net/download .
If you try it, let me know how you get on with it!
Allan
"mData": function ( source, type, val ) {
if (type === 'display') {
if (source.approved == "1") {
return '/* put the checkbox in here with checked="checked" */';
} else {
return '/* put the checkbox in here without checked="checked" */';
}
} else if (type === 'set') {
source.approved = val;
return;
} else
{
return source.approved;
}
}
Seems to work. Do you see any issues with that?
I couldn't get version 1.10 to work for me on first shot.
Looks okay to me.
> I couldn't get version 1.10 to work for me on first shot.
I would hugely appreciate if you could link me to a page showing the error with 1.10 so I can fix it before 1.10 is released.
Allan
http://debug.datatables.net/idafeq
What I think might be the problem is that you need to update the checkbox sort plug-in that you are using - try this: https://github.com/DataTables/Plugins/blob/master/sorting/custom-data-source/dom-checkbox.js
Allan