fnSort listener

fnSort listener

mikemakusmikemakus Posts: 9Questions: 0Answers: 0
edited September 2009 in General
Hi,

Is there a way to have a lister attached to the fnSort function ?

Something like

[code]onFnSort = function(){
$('#select').val("");
}[/code]

I would like to set the value of a select dropdown to null whenever I click on a column header in the datatable.

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,051 Site admin
    Hi mikemakus,

    There isn't a sorting listener at the moment (providing a generic method for this kind of thing will be the main driving force for the next major version of DataTables), but it can be achieved using one of several options:

    1. In fnDrawCallback, check the sorting array (oSettings.aaSorting) to see if it has changed - and if so then sorting has occured.
    2. Edit the core function "_fnSort" to call your function
    3. I could provide a callback function which is called when sorting occurs (rather like '2', but 'official').
    4. Remove the default event on the header elements and add your own which will do sorting and whatever else you require.

    I'm edging towards option 3 as this has been asked a couple of times before - I just don't want to open the flood gates for a callback on filtering etc etc. What do you think?

    Regards,
    Allan
  • mikemakusmikemakus Posts: 9Questions: 0Answers: 0
    Hi allan,

    A callback function would be great yes :)
    Until then I'll try the 1st option, which should do the trick.

    Thanks,
    Mike
This discussion has been closed.