live DOM sorting?

live DOM sorting?

joejoejoejoe Posts: 4Questions: 0Answers: 0
edited March 2010 in Plug-ins
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. :)

Replies

  • joejoejoejoe Posts: 4Questions: 0Answers: 0
    Oh. I'm stupid!

    It works after changing

    aData.push( this.value );

    to

    aData.push( $(this).text());

    :P
  • dh1dh1 Posts: 3Questions: 0Answers: 0
    my code works beautifully, now that i've found this post!
    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?
  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin
    The sorting function which is used for each column is based on the 'sType' for that column: http://datatables.net/usage/columns#sType .

    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
  • dh1dh1 Posts: 3Questions: 0Answers: 0
    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?
  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin
    It's not really supported behaviour - but what you could do is to set the sType for the column in the settings object. So something like:

    [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
This discussion has been closed.