what does fnSortListener do?

what does fnSortListener do?

joatmanjoatman Posts: 11Questions: 0Answers: 0
edited June 2011 in General
Hello,
After looking at different sorting examples, and implementing multi-column sort, i still can't figure out what the fnSortListener does. i have seen threads where the fnSortListener was initially suggested, but later deemed unnecessary.
can i look at an example of the fnSortListener being used?
Thanks,
Nilesh

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    http://datatables.net/api#fnSortListener

    Generally speaking fnSortListener shouldn't be needed - however it can be used to attach the DataTables sorting listener (the click event on each TH element in the header) to any element you wish on the page. This can be useful if you want to control the table sorting from somewhere other than the header - which is unusual but possible.

    I don't have an example running live of fnSortListener being used but there is a code example in the documentation.

    Allan
  • juxta52juxta52 Posts: 14Questions: 0Answers: 0
    Allan, how do I override the click event in the Column header? For instance, I want to be able to do Server Side Sorting on column click, but I wish to process some javascript, then make a rest call, and lastly redraw the table with the json string that is returned with a success call.... Is there a more efficient way of doing this or am I missing something?

    I am attempting doing Pagination a similar way using the example: ( http://datatables.net/release-datatables/examples/plug-ins/paging_plugin.html ). Where I am going to make a REST call upon click of next or previous to get a json object back of the data I wish to be rendered in DataTables.

    Meaning I have to update the tables meta data information (in the info, ex. "Showing X to Y of Z entries") accordingly with the meta data of the object that is returned from the server.

    The reason for all this is, there is already a REST service in place, one of my requirements is to try to utilize that call with minimal modifications, so for the most part I'm able to do pagination/column sorting/ect, but it uses a slightly different format than DataTables. Therefore, I need to process the return into something DataTables can use along with process the call to something that is meaningful to the REST call.

    Is there a more effective way of doing this?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > how do I override the click event in the Column header?

    You would unbind the default 'click' listener that DataTables adds and then add your own event handler that would call fnSort with the required values. Its not the most trivial piece of code, but its certainly possible to do it that way. fnSortListener isn't what you would want here, although you might code the code inside it useful if you wanted to replicate the exact behaviour.

    Allan
This discussion has been closed.