fnSortListener Issues
fnSortListener Issues
rsoberano44
Posts: 4Questions: 0Answers: 0
Hi, I'm using Datatables along with the rowGrouping plugin to display a list of products grouped by vendor. The way the table is now, you can sort product names and details under each vendor group by using the standard table sort events bound to the thead at the top of the table.
My issue is that I want to be able to make a copy of that thead under each group name so that users will be able to sort through the items in each vendor group without having to scroll all the way to the top (as this is a long list). Adding the row with the headings is fine, but I'm having mad issues trying to bind the sort event using fnSortListener to these headings, so I was wondering what the best way to do this is.
To clarify, the table is like this right now:
-------------------------------
Product Name Product Details
--------------------------------
Group 1 Name
Group 2 Name
Group 3 Name (expanded)
Product 1 Product 1 Details
Group 4 Name
--------------------------------
But I want it to be like this:
-----------------------------
Group 1 Name
Group 2 Name
Group 3 Name (expanded)
-----------------
Product Name Product Details <--- Want to be able to sort by these headings
------------------------
Product 1 Product 1 Details
Product 2 Product 2 Details
Group 4 Name
-----------------------------
My issue is that I want to be able to make a copy of that thead under each group name so that users will be able to sort through the items in each vendor group without having to scroll all the way to the top (as this is a long list). Adding the row with the headings is fine, but I'm having mad issues trying to bind the sort event using fnSortListener to these headings, so I was wondering what the best way to do this is.
To clarify, the table is like this right now:
-------------------------------
Product Name Product Details
--------------------------------
Group 1 Name
Group 2 Name
Group 3 Name (expanded)
Product 1 Product 1 Details
Group 4 Name
--------------------------------
But I want it to be like this:
-----------------------------
Group 1 Name
Group 2 Name
Group 3 Name (expanded)
-----------------
Product Name Product Details <--- Want to be able to sort by these headings
------------------------
Product 1 Product 1 Details
Product 2 Product 2 Details
Group 4 Name
-----------------------------
This discussion has been closed.
Replies
Allan
Ah - its probably recreating the DOM elements on each draw.
Unfortunately in this case, DataTables is using a static event listener (see _fnBindAction) so you would probably need to bind the sort listeners on every draw as well ( fnDrawCallback ). I'd probably suggest having a dig around in the column grouping plug-ins code and seeing where it is working with the draw callback and then making the modification in there, rather than doing it externally.
Allan
It works great now, thanks for all of your help and your quick replies!