Two DataTables on Sort Control

Two DataTables on Sort Control

gtsafasgtsafas Posts: 13Questions: 0Answers: 0
edited March 2010 in General
I am currently using two datatables and I would like that when I sort one it applies the same sort to the other, IE table1.col1 sort asc triggers table2.col1 sort asc


I would also like to know how to remove the header as I will only need one.

Thank you ahead of time.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There are a couple of ways to do this - although given the circular dependance, I think the best way would be to make use of fnPageChange http://datatables.net/api#fnPageChange (not there is a bug in 1.6.1 with this function - if you want a copy of the development version of 1.6.2 which fixes this, please drop me a line at http://datatables.net/contact . It should be released in a day or two - I've just got a few little things to finish off.

    What you would do is unbind the sorting event handlers DataTables puts on the headers, and then you would put your own on them which will sort both tables.

    Regarding the header removal - DataTables rather expects it to be there - so this would be unsupported behaviour. But what I think you could do is just removeChild() on the THEAD (to remove the TR) once the table has been fully initialised. But never tried it... :-)

    Allan
  • gtsafasgtsafas Posts: 13Questions: 0Answers: 0
    Thanks Allan,

    This sounds perfect. I will wait for official release
  • gtsafasgtsafas Posts: 13Questions: 0Answers: 0
    On second glance, I am not using pages. I am showing all data at once. Is there another way to do this? Should I use fnUpdate?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think that even with pagination switched off, that fnPageChange is the way to go with this (and it works in the 1.6.2 release now :-) ). So I'd still remove the default listeners and add your custom ones to sort both tables.

    fnUpdate is used to update data to the table, rather than as a callback.

    Allan
This discussion has been closed.