Is it possible to disable/enable column sorting programmatically?
Is it possible to disable/enable column sorting programmatically?
Hi,
I made a plugin which allows to sort columns of a datatables, by dragging the border of a th element.
I took most of the code from this discussion: http://datatables.net/forums/discussion/2474/column-resizing/p3
I finally have something that works well, except that when I release the mouse button after the drag and drop, a sorting happens on the columns.
I would like to disable the sorting temporarily, so that there is no column sorting after I finish resizing a column.
I tried to find a function in the API, I tried to look in this forum, without success.
Is there a way to achieve it?
Thanks a lot.
Replies
You might need to call
event.stopProagation()
to stop the click event bubbling up to DataTables. If you post an example, that might let us take a look and see what is happening.Allan
I tried but it did not work.
Like in ColReorder plugin, my plugin binds a "mousedown" and a "mouseup" event on the
<th>
element.When I click on a th element to sort the appropriate column, it seems to me that the sorting happens in the mouseup callback. So I tried to do
e.stopPropagation()
from my_fnMouseUp()
function, without success. Then I also tried to do it from the_fnMouseDown()
function, but no success either.I cannot post the full example, but here is the idea:
Wherever I put this
e.stopPropagation()
, the column sorting is still performed.I don't understand in the ColReorder plugin, why the sorting is not performed when clicking on a column to reorder it?!
I would need to do the same in my plugin, but cannot figure out how it's done in the ColReorder plugin.
It might be this - although i'd need to experiment to be sure (I has been a while since I've worked on that bit of code).
Allan
Hello allan,
I haven't had time to try it yet, but I will soon and I will give a feedback here.
Thank you!