How to eliminate rowspan="1" colspan="1" in header cells?

How to eliminate rowspan="1" colspan="1" in header cells?

blagblag Posts: 18Questions: 0Answers: 0
edited January 2012 in DataTables 1.8
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?

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    They aren't essential, but they make life a lot easier (particularly when dealing with headers that have rowspan / colspan attributes in them and column visibility options), and they are also harmless. Why do you want to remove them? I don't see that they have any negative side effects?

    Allan
  • blagblag Posts: 18Questions: 0Answers: 0
    The tables on which I am using DataTables are simple. They have no caption, one row of headers, no header cells in the body, and one footer which spans all the columns, there are no hidden columns, and each and every header cell - and each and every cell in the body spans one cell and one row, no more and no less - ever.

    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.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > minimise

    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
  • blagblag Posts: 18Questions: 0Answers: 0
    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?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Hah! Good stuff :-)

    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
  • blagblag Posts: 18Questions: 0Answers: 0
    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...
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    up - that's basically the point. In fairness DataTables is already a lot smaller than a number of other table enhancing libraries, and 1.9 is actually a bit smaller than 1.8.2, despite all the new features - so this is something that I'm working on, but ultimately, yes you might not need a fair number of the features DataTables provides.

    Another advantage of open source software :-)

    Allan
  • blagblag Posts: 18Questions: 0Answers: 0
    Dollars in my Paypal account, and have now made a donation.

    I've reduced the DataTables code down to 13K!!
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Thanks very much for the donation - hugely appreciated!

    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
  • blagblag Posts: 18Questions: 0Answers: 0
    13K minified, but not Google closuer 'advanced' minification.

    You burst my bubble - I thought I was doing really well!!

    Damn! I'll have to do more work...
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Heh - sorry. I might be wrong, and in fairness it would probably take a good amount of work! :-)

    Allan
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    Actually I would love to be able to avoid that empty THEAD for cosmetic/esthetic reasons. I end up with a small, empty row on top of my table that I'd like to get rid of.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Sorry I might be missing something from the old conversation, but what empty header? Can you link me to an example please?

    Allan
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    Hi 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.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    DataTables currently can't dynamically add and remove columns, so you can't have a table without any columns in it (since it would then never have any columns in it).

    Allan
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    Allan. It does have columns, it just doesn't have a header, which gets added by datatable.
    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.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    edited April 2012
    I'm a bit confused I'm afraid - are you saying you don't want a header in the table? Could you either give me a link, or set up an example using http://live.datatables.net showing the problem please?

    Thanks,
    Allan
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    I'm not sure what's going on. This example:
    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?
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    Here is a screenshot:
    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...
  • timtuckertimtucker Posts: 48Questions: 0Answers: 0
    Could you use css styling to set the datatables-generated thead to display: none ?

    i.e.:
    [code]
    #details-notes-table thead {
    display: none;
    }
    [/code]
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    @Tim: sure could, thanks, I guess I was also wondering why a THEAD ended up in the DOM :)
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    > Yes, I do not want a header if I don't specify a header

    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
  • sebastienbarresebastienbarre Posts: 24Questions: 1Answers: 0
    No problem. Thanks guys.
This discussion has been closed.