api.columns.adjust().draw() doesn't work on hide/show column (when two rows in header)

api.columns.adjust().draw() doesn't work on hide/show column (when two rows in header)

sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2
edited December 2015 in Free community support

On initialization of DataTable - the column header (with two row) is aligned and width is set properly.
Though - when i try to show/hide a column - the column doesn't adjust. The new unhidden column is weirdly added to the table.
I tried calling "api.columns.adjust().draw()" or "api.columns.adjust().draw(false)" - the columns are not adjusted.

Please note, the above scenario works fine - when we have single column. The problem is with two columns.

Answers

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2
    edited December 2015

    Please note, the above scenario works fine - when we have single row in a header. The problem is with two rows in a header.

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2
    edited December 2015

    I have found a solution for my problem. The change is required at function _fnGetUniqueThs()

        function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
        {
            var aReturn = [];
            if ( !aLayout )
            {
                aLayout = oSettings.aoHeader;
                if ( nHeader )
                {
                    aLayout = [];
                    _fnDetectHeader( aLayout, nHeader );
                }
            }
    
            for ( var i=0, j=0, iLen=aLayout.length ; i<iLen ; i++ )
            {
                for (var jLen=aLayout[i].length ; j<jLen ; j++ )
                {
                    if ( aLayout[i][j].unique &&
                         (!aReturn[j] || !oSettings.bSortCellsTop) )
                    {
                        aReturn[j] = aLayout[i][j].cell;
                    }
                }
            }
            return aReturn;
        }
    

    Initialize the variable 'j' together with 'i' - this way it will give all the column from the multiple row at header.

    @Allan: Can you check, if this is okay to be updated at plugin level. Might be useful for others who work with complex header and dynamic show/hide of a column.

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Could you post a link to a test page that shows the issue please? I don't quite understand why that change would resolve the issue (I'm slightly concerned it might introduce new issues since j is not being reset for each loop).

    Allan

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2

    It's a long code - will spend sometime and prepare that for you. hopefully next week.

This discussion has been closed.