Slickgrid: Final column autosize to use all remaining space

后端 未结 2 1527
无人及你
无人及你 2021-01-14 00:04

I\'m using SlickGrid and struggling to find an elegant solution to the following:

  1. All columns must have a specific initial width when first rendered but be res
2条回答
  •  无人共我
    2021-01-14 00:18

    I know it's kind late for this reply.

    But i've managed to do that without having to change things at slick.grid.js or set min/maxWidth at columns array.

    Instead what i did was to iterate through the columns array adding the values of "width" field of each column and then i've did a simple math count to set the last column width as innerWidth - totalColumsWidth + lastColumnWidth.

    Code:

    function lastColumnWidth(columns)
    {
            var widthSum = 0;
            angular.forEach(columns, function(col) {
                if(col.width) { widthSum = col.width + widthSum; }
            });
            if(window.innerWidth > widthSum) {
                columns[columns.length-1].width = columns[columns.length-1].width + (window.innerWidth - widthSum);
            }
            return columns;
    }
    

提交回复
热议问题