How to eliminate rowspan="1" colspan="1" in header cells?
How to eliminate rowspan="1" colspan="1" in header cells?
blag
Posts: 18Questions: 0Answers: 0
DataTables 1.8 is adding
[code]
rowspan="1" colspan="1"
[/code]
as in
[code]
Quantity
[/code]
to all the header cells of tables to which the DataTables script applies.
Are these ESSENTIAL to the functionality of the script?
If they are not essential, how do I prevent them from being added?
[code]
rowspan="1" colspan="1"
[/code]
as in
[code]
Quantity
[/code]
to all the header cells of tables to which the DataTables script applies.
Are these ESSENTIAL to the functionality of the script?
If they are not essential, how do I prevent them from being added?
This discussion has been closed.
Replies
Allan
Whilst I acknowledge that these rowspans and colspans are not a significant addition to the html, and that they do not have a negative effect, they are, nevertheless, an addition, and if they are NOT necessary, I feel that, in my case, it becomes difficult to justify them. I try to optimise and minimise my code wherever possible, and maybe I'm a bit obsessive about this.
Therefore, I would prefer not to have this (apparently) 'pointless' html - PLEASE, PLEASE advise as to how I might prevent them being created and added to my table.
These two attributes will have absolutely no effect on the code sent from the server since they are added client-side
> optimise
I don't see how removing them would make any difference to the speed of execution. The browser is going to look for the attributes away and when it doesn't find them it would fall back to its default, so an argument could even be made that it is better for performance to have them (although no one would ever see the difference!).
Personally I don't see the problem with the attributes being there, as it is something the end user is never going to see, and it has no negative impact on performance, but a positive impact for development (indeed, you save a few bytes in DataTables this way since it doesn't need to consider removing the attributes at any point!).
however, I perfectly understand that you want to remove them - no problem at all. All you need to do is define an fnDrawCallback function that will loop over the elements in the header and remove the colspan and rowspan attributes. The other option is to modify DataTables core to have it simply not add these attributes.
Allan
Thanks for the comprehensive response. I could add a function to remove them, I suppose, but you're absolutely correct - that wouldn't improve anything. I'm using the minified version, so I'll take a look at the non-minified version to see if I can find the relevant code an remove it from the core.
Found it, done it. After much work,
Great work by you, by the way!!
When I get some pennies in my PayPal account I'll send you some!!
Pause...
I have also removed most of the features that are not relevant to my specific needs - the code is down to an anorexic 19k!!
Obsession: a blessing or a curse?
My plans for DataTables is to make it a whole lot more modular, so you can customise it as much as you want, by including or removing modules. For example if you don't want filtering you simply wouldn't add in the filtering module.
DataTables 1.9 starts on this development path and 1.10 will continue on it, although probably not complete it. It will hopefully also make it easier to build plug-ins such as FixedColumns etc for developers. Its a long term plan :-)
Allan
A modular build tool would be fantastic - you've probably got most of the features that anyone could need, but the downside is that those of us (the majority?) who don't need all the features have a comparatively large file (minified at 70K on my disk). jQuery 1.7.1 (minified) itself is only 92K.
I suspect that there are still superfluous elements in my pared-down version, but when I get a moment or two my obsession will inevitably drive me to try to get it slightly smaller.
No pennies in my PayPal account yet...
Another advantage of open source software :-)
Allan
I've reduced the DataTables code down to 13K!!
Is that 13K minified? I always through that for server-side processing alone it could be absolutely tiny - 2-3K I would imagine it could be got down to - depending on the features needed of course...!
Allan
You burst my bubble - I thought I was doing really well!!
Damn! I'll have to do more work...
Allan
Allan
I have a table that has *no* header. As soon as I call datatable( ) on it, the following HTML is added:
and this appears as a small, empty row.
Allan
Here is the full table, as seen by Firebug:
[code]
01/25/2012 05:32:01 pm
Mark Jones replied: If this is domestic travel for the...
[/code]
However I needed added that thead, it was added by datatables.
Thanks,
Allan
http://live.datatables.net/ulehes
where I removed the THEAD shows that there is no THEAD once rendered. I'll try to replicate mine.
Yes, I do not want a header if I don't specify a header, which... well it seems that would make sense, right, why would a header appear when it's not needed :) The issue is that my THEAD is CSS-styled, it has some internal margin/padding, borders, etc, so it *does* show as a small, strange empty row when there is actually no TH in it (since I had no THEAD at all, and datatable added an empty one). Does it make more sense?
http://imageshack.us/photo/my-images/685/testly.png/
See white band on top of the table? Not a huge deal, but would rather not have it...
i.e.:
[code]
#details-notes-table thead {
display: none;
}
[/code]
Ah I see - that's not a situation that I've actually ever encountered before with DataTables, and the code was not designed for this use case I'm afraid. DataTables will always insert a header at the moment, if it doesn't find one, as I've made the assumption (possibly incorrectly) that a THEAD and TBODY will always be in the table and TFOOT is optional.
I'll add this to my list of feature requests for DataTables :-).
Until then, timtucker's solution would be the way forward.
Regards,
Allan