Sort programmatically

Sort programmatically

neuDev33neuDev33 Posts: 11Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I've just about started using DataTables and wanted to integrate a custom menu in my table. So far, I've successfully implemented a basic DataTable and gotten my custom menu displayed(by right clicking on column headers). This menu has options for sorting, grouping, hiding columns. I wanted to know how I can sort the datatable when the user clicks on a menu item. I tried

[code]$('#myTable').dataTable({ "aaSorting": [[3, "asc"]] });[/code]

However, this gives me an error saying i cannot reinit the table. Fair enough. But how do i access it's instance and sort it based on any column i wish through code?

Replies

  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    I believe you are looking for this: http://datatables.net/api#fnSort

    Assign your datatable to a variable and then you can control the sorting through fnSort.
  • neuDev33neuDev33 Posts: 11Questions: 0Answers: 0
    Exactly what I needed! Thank-you!
  • neuDev33neuDev33 Posts: 11Questions: 0Answers: 0
    Another doubt, how can I find out whether the current column has been sorted ascending or descending?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    table.fnSettings().aaSorting will tell you the current sort state, but dont write to that parameter, only read from it!

    Allan
  • neuDev33neuDev33 Posts: 11Questions: 0Answers: 0
    Thanks alot Allan!
This discussion has been closed.