Preserve original ordering but also bSort=true?

Preserve original ordering but also bSort=true?

gilescgilesc Posts: 2Questions: 0Answers: 0
edited August 2010 in General
Hi, I'm creating a DataTable client-side by transforming an HTML table. I want this table to be sortable by the user, which I can do with bSort=true, BUT I'd like the table to be initially presented in its original ordering within the HTML. Currently, when I set bSort=true, and don't provide sort columns, the table is automatically sorted by column 0.

Alternatively, is there any way to initialize a DataTable within the rather than the of a page? Being able to do either of the above would solve my problem.

Many thanks.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You can set aaSorting ( http://datatables.net/usage/options#aaSorting ) to be an empty array ( [] ) on initilaisation to stop the default sorting.

    Also you can have the DataTables initialisation anywhere - as long as the DOM has loaded ($(document).ready() is one way, putting the scripts at the very end of the body is another).

    Allan
  • sd_zuosd_zuo Posts: 78Questions: 1Answers: 0
    BTW, is it possible to revert back to the original order of the table?
    For example, clicking the column header first time, sort asc, second time, desc, third time, revert to original.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yes indeed it is possible - there is an API function to achieve exactly that kind of sort: http://datatables.net/plug-ins/api#fnSortNeutral . To have it 'activate' on the third click though, you would need to modify the sorting event handler that DataTables puts onto the table header.

    Allan
This discussion has been closed.