Bugfix for colReorder move() when using fixed table-layout

Bugfix for colReorder move() when using fixed table-layout

awelchawelch Posts: 38Questions: 1Answers: 3

When using a fixed table layout without scrollX moving columns while a column is not visible will cause the table to grow too large if the hidden column is later made visible again. I've created a JS Bin showing the behavior. This happens because the fnColReorder function makes a call to _fnColumnOptions to recreate the get/set functions which has the unintended (I believe) side effect of setting the sWidthOrig property for all the columns (since the columns have a width in the DOM). The fix I have used is to copy the get/set code from the _fnColumnOptions function into the fnColReorder function. See below:

$.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop, invalidateRows )
{

...

  // regenerate the get / set functions
  //for ( i=0, iLen=iCols ; i<iLen ; i++ ) {
      //oSettings.oApi._fnColumnOptions( oSettings, i, {} );
  //}
  $.each(oSettings.aoColumns, function (index, oCol) {
      var mDataSrc = oCol.mData;
       var mData = oSettings.oApi._fnGetObjectDataFn(mDataSrc);
       var mRender = oCol.mRender ? oSettings.oApi._fnGetObjectDataFn(oCol.mRender) : null;
  
       var attrTest = function (src) {
           return typeof src === 'string' && src.indexOf('@') !== -1;
       };
       oCol._bAttrSrc = $.isPlainObject(mDataSrc) && (
           attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter)
       );
       oCol._setter = null;
 
       oCol.fnGetData = function (rowData, type, meta) {
       var innerData = mData(rowData, type, undefined, meta);

        return mRender && type ?
            mRender(innerData, type, rowData, meta) :
            innerData;
        };
        oCol.fnSetData = function (rowData, val, meta) {
            return oSettings.oApi._fnSetObjectDataFn(mDataSrc)(rowData, val, meta);
        };
  });

...

}

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @awelch ,

    Thanks for that. I've added a unit test to catch this in the future. Once fixed, we'll report back here.

    Cheers,

    Colin

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Yup - thank you. ColReorder really needs a rewrite at some point!

    Allan

This discussion has been closed.