Rowspans Cause DataTables to Fail

Rowspans Cause DataTables to Fail

smg6511smg6511 Posts: 12Questions: 2Answers: 0
edited July 2009 in General
I have a particular table where some of the TDs in the first column span multiple rows. DataTables doesn't appear to like this, failing to work, and shows an error in Firebug:

sData is undefined
.../jquery.dataTables.min.js
Line 68

Is there a method for dealing with this? I tried setting bSort to FALSE, but that didn't do the trick. Any pointers are appreciated :)

Cheers!

Replies

  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    Hi smg6511,

    You are quite correct that rowspans will cause difficulties for DataTables. The reason for this is that DataTables treats each row as an independent entity - there are some tricks such as row grouping which can be used through the API: http://datatables.net/1.5-beta/examples/advanced_init/row_grouping.html , but genuine support for rowspan is a non-trivial exercise. How, for example should this be handled with regard to sorting and filtering? It would probably require quite a large change to DataTables to directly support this from the HTML. Sorry I can't give better news!

    Regards,
    Allan
  • smg6511smg6511 Posts: 12Questions: 2Answers: 0
    Allan,

    I figured it was a tall order ... Unfortunately, I'm still too fresh to the JS world to be of much help :)

    As a compromise solution, is it possible to alter how the plugin relies on the sortability of the data so that if one disables sorting via bSort on a table with rowspans, the pagination and striping features will still work?

    Thanks for your input and the terrific plugin!

    Cheers,
    Jim
  • smg6511smg6511 Posts: 12Questions: 2Answers: 0
    One more thing I've noticed just now, if you set the scope of any within the (i.e., ), that kills the plugin as well. No problem, however, if you set the scope of a within the same context...
  • smg6511smg6511 Posts: 12Questions: 2Answers: 0
    OK, sorry Allan, my bad on the last note! Once I scoped the s in the properly, it worked fine (using 1.5b9)...
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    Hi smg6511,

    Regarding the rowspans - I'm afraid there really isn't anyway to get this working with DataTables as it stands at the moment, with or without sorting or filtering. The reason for this is that, as I say, DataTables treats each row as an independent entity - they have no ties with other rows, and as such rowspans will cause it to fall over. I did a prototype hack a while ago for colspans which was a bit easier than row span, and I'm considering putting that into the main distribution, but rowspan is not so easy... sorry :-)

    Regarding the scope - it thin it's probably the TH inside TBODY that is actually tripping DataTables up - it expects TH elements in THEAD (you can put in TDs for some tricks as well!) and only TD in TBODY. If you want you can add classes to the TD elements inside TBODY to make them look more header like!

    Regards,
    Allan
This discussion has been closed.