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) :
        oCol.fnSetData = function (rowData, val, meta) {
            return oSettings.oApi._fnSetObjectDataFn(mDataSrc)(rowData, val, meta);




  • colincolin Posts: 14,709Questions: 1Answers: 2,511

    Hi @awelch ,

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



  • allanallan Posts: 58,289Questions: 1Answers: 9,325 Site admin

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


This discussion has been closed.