Adding another header row
Adding another header row
peterkronenberg
Posts: 112Questions: 0Answers: 0
Allan,
How can I add another header row? Datatables is building the header. There doesn't seem to be away to add another row.
I want to use it as individual column filters as in http://datatables.net/examples/api/multi_filter.html. I know there has been a lot of previous discussion about putting these filter controls in the header as opposed to the footer. It's not clear if all the issues have been resolved, e.g., for hidden columns
How can I add another header row? Datatables is building the header. There doesn't seem to be away to add another row.
I want to use it as individual column filters as in http://datatables.net/examples/api/multi_filter.html. I know there has been a lot of previous discussion about putting these filter controls in the header as opposed to the footer. It's not clear if all the issues have been resolved, e.g., for hidden columns
This discussion has been closed.
Replies
Allan
When I needed to iterate through hidden TDs, you pointed me to fnGetTd and fnGetTds. Is there a similar option for the header?
A cleaner approach might be to simply create an HTML table and then initialise DataTables on that.
Allan
Directly modifying the DOM is fine for visible data, but if DataTables is going to support hidden columns, which is a great feature, there need to be more api's to handle that hidden data.
I'm not sure yet if I'll go this route. Can you give me a brief synopsis of how anThExtra is used? Does it basically contain all the TH's in a TR? Will it be ok to have 2 rows of TH's or does the 2nd row need to use TD?
Would I have to call fnReDraw after I add the row?
This isn't quite right. DataTables will create all TR elements that are needed in order to display the table. There are trade offs for using aaData (as you are finding out...), it can sometimes be faster, but equally there are times when it can actually be slower (reading the DOM v creating it) and generally less flexible. DataTables is mainly focused on progressive enhancement, rather than creation of DOM elements, which is why this isn't possible at the moment, nor is it likely to be added to the core (a plug-in might be an option).
> Can you give me a brief synopsis of how anThExtra is used?
Basically it's one element in the array for each extra row (note that colspan / rowspan will throw it out completely and are not supported for hidden columns). So if you had two TR elements in THEAD there would be one extra TH to have in the extras array.
I personally wouldn't modify anThExtra externally in my own projects, although as I mentioned it is possible to do - just messy and if I change it, it would break your app (it's an internal variable so no guarantee it won't change - although obviously it wouldn't be done lightly...).
Allan
Is it still true that this won't support multiple rows in the header? Does the ColVis plug-in support this or setting bVisible to false?
Allan
Is the ColVis example posted yet?
Allan
What's the difference between that and looping through oSettings.aoColumns[].nth?
Not yet - they will be publicly visible when that software is released. Until that time you can check the code out from Github and get all the examples.
> _fnVisibleToColumnIndex
This is an internal method (hence the underscore indicating it should be treated as such), so it's not documented anyway other than the code comments - although it can still be useful :-). It's not a defined public function for the same reason as most of the other internal functions, they don't need to be. But it is accessible and could be accessed using a plug-in API function if you wanted a proper public API.
> What's the difference between that and looping through oSettings.aoColumns[].nth?
That is effectively that this method does - it just does all the leg work for us. No point it rewriting existing code :-)
Allan
Allan
When I create a second header row using TD's, FixedHeader gives me an error at initialization:
[code]
jQuery("thead:eq(0)>tr th:eq(" + i + ")", nTable)[0].style.width is not a function
Line 658
[/code]
Seems to work ok with TH, but it's early still :-)
Any ideas?
This is basically a limitation of the current implementation of FixedHeader as it stands at the moment. Oddly enough just a couple of days ago I committed a change to FixedColumn so that it doesn't have this problem, and something similar can probably be done for FixedHeader in future. I've added it to my to-do list.
Allan
I guess the other option would be not to use a keyup handler and just have the user press enter after he has completed his search term. I'll no longer have the cool real-time update, but at least it will work.
I recently put together an example of individual column sorting with FixedColumns and ColReorder, and it's fairly cool :-). So something that is worth adding to FixedHeader in future.
Allan
[code]
if (e.which !== 13) {
return;
}
[/code]
which only does the filtering when the user presses enter. Although functionally it works, it's still not user-friendly because the search term is no longer visible to the user, since FixedHeader has rebuilt the cell.
Drat.
Allan
Allan
Allan