How do I autosize the column in SlickGrid?

前端 未结 7 1278
情歌与酒
情歌与酒 2020-12-08 00:25

I want slickgrid to autosize the columns based on the widest content or header text - whichever is wider. In simpler terms, I want it to simulate the default behavior of reg

相关标签:
7条回答
  • 2020-12-08 00:49

    Insert the text into an off-screen element and retrieve the width of the element. This is what excanvas does to measure text. Use this to set the width of the column since it's expecting a pixel value.

    0 讨论(0)
  • 2020-12-08 00:56

    When constructing your options, you can use forceFitColumns: true

    var options = {
        enableCellNavigation: true,
        forceFitColumns: true
    };
    

    This will make the columns fill the entire width of your grid div.

    0 讨论(0)
  • 2020-12-08 01:01

    Make this simple adjustment to Naresh's https://github.com/naresh-n/slickgrid-column-data-autosize, on the init function:

    • Add $container.ready(resizeAllColumns); to the init function.

    This ensures the columns autoresize on initial load

    0 讨论(0)
  • 2020-12-08 01:06

    Slickgrid will not support column auto size based on data.You need to write a plugin or fork the slickgrid core to modify.

    Here is the link I have created a plugin to handle slickgrid auto size https://github.com/naresh-n/slickgrid-column-data-autosize

    0 讨论(0)
  • 2020-12-08 01:06

    You should be able to call the autosizeColumns() method of the grid object.

    grid.autosizeColumns();
    
    0 讨论(0)
  • 2020-12-08 01:14

    I added this after the grid is drawn and it works fine.

    $(window).resize(function() {
    var cols = grid.getColumns();
    grid.setColumns(cols);
    })
    
    0 讨论(0)
提交回复
热议问题