datatable Warning: Cannot reinitialise Datatable (need to disable sorting)

datatable Warning: Cannot reinitialise Datatable (need to disable sorting)

merlin2049ermerlin2049er Posts: 6Questions: 2Answers: 0

Hi, I have a datatable I'm trying to disable the sorting option from (sorting on the server side). But, we have a partial that initializes the datatable, and I can't seem to figure out how to just disable the ordering after it's already been initialize.

I tried, $('#datatable').DataTable({ "retrieve": true, "ordering": false});
but that does not work.

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    I can't seem to figure out how to just disable the ordering after it's already been initialize.

    I don't believe there is a way to disable ordering after the Datatables has been initialized. To disable ordering you will need to use ordering during the initialization of the Datatable. Use the Single initialization technique by placing "ordering": false in your original Datatables initialization.

    Kevin

  • merlin2049ermerlin2049er Posts: 6Questions: 2Answers: 0

    We have a routine that renders the partial datatable and allows for filtering in each column. They would like that first row sorted descending (datetime field).

    I'm not sure what my options are.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Use columns.orderable to disallow the users from ordering the table. This will still allow Datatables to order the table via order() and order. Set the initial table order you want to order and set columns.orderable false for all columns using option columnDefs with columnDefs.targets set to _all.

    Kevin

  • merlin2049ermerlin2049er Posts: 6Questions: 2Answers: 0

    ok, I've set the order by on the server side. I don't require datatables to sort asc on the first column. I need to get sorting to work with our filtering routine.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    I don't require datatables to sort asc on the first column

    Set the order option to what you want the initial table order to be. See the examples in the docs for ideas.

    I need to get sorting to work with our filtering routine.

    Sorry, I'm not clear what this means. If you want to set the table order based on what filters are chosen you can use order() to change the table order. If this doens't help please provide more details.

    Kevin

Sign In or Register to comment.