Fix for Colspan

Fix for Colspan

CrypticCryptic Posts: 2Questions: 0Answers: 0
edited August 2012 in General
After working with dataTables for some time and loving it, I found that not having colSpan was making some of my more complex table layouts next to impossible to do...so I got the unminimized source for DataTables 1.9.3 and began to mess around. Suffice it to say, I've implemented a fix for using colspan in the body of a table. There are some tradeoffs, however...as Allan has pointed out every other time this comes up. You cannot sort or do anything like that (search may not even work very well, if at all...I'm not sure, my implementation doesn't use it very much), but for many people, that may be alright....so, here is the code:

The changes I made were in the function "_fnGatherData( oSettings )" beginning on line 515:
[code]function _fnGatherData( oSettings )
{
var iLoop, i, iLen, j, jLen, jInner,
nTds, nTrs, nTd, aLocalData, iThisIndex,
iRow, iRows, iColumn, iColumns, sNodeName,
oCol, oData;
/*
* Process by row first
* Add the data object for the whole table - storing the tr node. Note - no point in getting
* DOM based data if we are going to go and replace it with Ajax source data.
*/
if ( oSettings.bDeferLoading || oSettings.sAjaxSource === null )
{
nTrs = oSettings.nTBody.childNodes;
for ( i=0, iLen=nTrs.length ; i

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Hi - this is really excellent. Thanks for sharing your solution for this with us!

    I would emphasis to others that this is not a core part of DataTables, nor is it likely to be in the near future with the development resources that can currently be put into DataTables (i.e. my time :-) ). This will break several features such as sorting, column filtering, column visibility, probably TableTools etc as well. However, if you understand the changes and are willing to except the trade-offs and that this is unsupported, this is a really nice way of implementing colspan.

    The goal for DataTables long term is certainly to support this kind of thing - but that's a very long term goal :-)

    Allan
This discussion has been closed.