Enable / Disable Column Sort functionality after table initialization

Enable / Disable Column Sort functionality after table initialization

birdiebirdbirdiebird Posts: 1Questions: 1Answers: 0

I am attempting to build functionality into a site where non-registered users have limited functionality (i.e. cannot sort table) but when they are logged in I enable the sorting functionality.

I would prefer to tie the enable / disable of the sorting outside the initialization of the table. I have come across solutions that have quickly disabled the functionality by removing the click event from the table headers, but I do not have a clear solution how to re-enable the sorting after it has been removed.

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    I assume that the page is reloaded when the user is logged in (i.e. it doesn't go from logged out to logged in without a refresh)? If so, just use ordering or columns.orderable (first completely disabled all ordering, the second just the user ability to order).

    However, if it can go from logged out to logged in without a reload (and therefore a table reinit) then you could use order.listener() to attach the event listener DataTables uses for ordering.

    Allan

This discussion has been closed.