live DOM sorting?
live DOM sorting?
I'm checking the DOM sorting example at "http://datatables.net/examples/plug-ins/dom_sort.html".
I'll make the first column elements dynamic with some PHP code.
I'm wondering how to get each element in the tag, such as "Gecko", "Gecko", etc.
The following code doesn't work.
$.fn.dataTableExt.afnSortData['dom-try'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+')', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.value );
} );
return aData;
}
Any help is greatly appreciated. :)
I'll make the first column elements dynamic with some PHP code.
I'm wondering how to get each element in the tag, such as "Gecko", "Gecko", etc.
The following code doesn't work.
$.fn.dataTableExt.afnSortData['dom-try'] = function ( oSettings, iColumn )
{
var aData = [];
$( 'td:eq('+iColumn+')', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
aData.push( this.value );
} );
return aData;
}
Any help is greatly appreciated. :)
This discussion has been closed.
Replies
It works after changing
aData.push( this.value );
to
aData.push( $(this).text());
:P
For my next trick, i want to be able to use the same kind of sort function but from an external link. is this possible?
I have a UL containing 3 list items in each cell of one of my columns -- i use a modified version of the DOM sorting function to get the desired list item, like this:
$('td:eq(' + iColumn + ') ul li.Choice1, oSettings.oApi._fnGetTrNodes(oSettings)).each(function() {
aData.push($(this).attr('title'));
i have three functions, to handle li.Choice1, li.Choice2 and li.Choice3 -- how do i tell my dataTable to change the kind of sort used for a given column, and resort according to that choice? Do i need to destroy and recreate my dataTable with the new Sort Type?
The sType name is used to pick out the required sorting function (for example 'dom' in the example at the bottom of this page: http://datatables.net/development/sorting ). You can rename that to whatever you want, and have as many as you want.
Allan
Thanks for replying so quickly. The documentation was just perfect for getting me to this point -- i've created the sort functions, and if I set any of them for the initial sort, it works fine. The problem is that when i try to change the sType for a given column after the data's been loaded, i can't use the .datatable() function again -- i get a message saying "DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required".
How do i specify a different "sort key" after the table has been initialized?
[code]
oTable.fnSettings().aoColumn[0].sType = "whatever";
[/code]
would change the sorting type. Then just resort the table to have it take effect. But as I say, this wasn't an expected interaction :-)
Allan