Sort controls customization
Sort controls customization
Razorblade
Posts: 12Questions: 3Answers: 1
Hi everyone,
when rendering, Datatables adds the sort controls only in the TH tags that are within the last TR in the THEAD.
I would like to render sort controls not in the last TR, but in a TR that I'll decide.
It is possible to do such customization? How?
Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Could you possibly override the datatables classes, names or IDs in your table? So you would override which tr's the datatable has control of? I'm not sure if that would work, but worth a shot maybe.
Hi @Modgility,
inspecting the DOM what I've seen is that Datatables adds 'class="sorting"' to the THs, so I've proceeded to manually add this class but nothing changed, sort controls still render only at the last TR. :(
I'm now tring to do the fix using css..
-[I think that styles are completely overridden by Datatable for thead at least, so I'm stuck with this issue :)]
Nope, it is possible to work using css.
Hope someone can help with some advice :)
Cheers
Here my dirty solution waiting for someone that has a better one,
at initComplete I'll take the whole TH with sorting and move it wherever I need it to be.
Two options:
orderCellsTop
option can be used to make the DataTables attach the listener to the top row rather than the bottom.order.listener()
method to apply a listener to any element on the page you want!Allan
Hi @allan,
thank you for your answer, your link to 'order.listener()' method bring to a 404 page but I was able to find the correct page (http://datatables.net/reference/api/order.listener%28%29) after a search.
This method is really flexible and it's working, when I press my custom buttons, the last TR with default controls is correctly re-rendered (also using multicolumn sorting) but what I am now missing is how to render current sorting state for each column, could you please help me with this issue?
Thanks!
I suppose I have to read the 'order' request parameter and then do my custom rendering, perhaps in a 'draw' callback...
Nevermind,
I've seend only now that the third option is a callback so I can do my rendering here inside :)
Cheers
Below my final solution, I'm posting it here because perhaps can help somebody and also because I'd like to receive some feedback, perhaps can be enhanced.
I'm using this code within an object instance that runs inside an AngularJS directive, so 'this' refers to the object and 'this.element' is the directive DOM element.
Launching this method below also at 'initComplete' callback will correctly render the custom sort control using initial sorting configuration.
I'll taking sorting data using the 'aaSorting' property, don't know if there is a getter to get this data.
Oops - thanks for point out the link error. Fixed now.
There is one more option for how to display the sorting - listen for the
order
event and then apply whatever styling is needed. That will also then work should you decide to use theorder()
method or any thing else that triggers a reorder.Allan