How to launch GridX column width recalculation after the grid has been started up?

自闭症网瘾萝莉.ら 提交于 2019-12-06 11:47:20

问题


According to documentation:

https://github.com/oria/gridx/wiki/Create-the-Simplest-Gridx

Never forget to call grid.startup(), since the column width calculation and layout rendering need to access the geometry information of grid DOM nodes.

If I have the grid with columns, that have no width specified, and autoWidth is set to false, startup() calculates the size of columns so, that they fill the whole viewport horizontally. However, if viewport is expanded, and extra empty space is inserted after the last column. If the viewport is narrowed, the last columns are not more visible (and no scroll is rendered).

So I think the best workaround is to launch the recalculation of columns sizes manually, after the viewport was resized. But I can't find an API method to do that.

How to call column width recalculation and layout rendering on existing grid?


回答1:


What I've done for this situation is setup an event handler to watch for window resize events, then set the width to the current grid width. When creating the grid:

function _resizeToWindow(grid, gridId) {
  grid.resize({w: dom.byId(gridId).offsetWidth, h: undefined});
}

on(window, "resize", function() {
  _resizeToWindow(grid, gridId);
});

It looks a little odd to resize the grid to the current width of the grid, but calling that function will cause the grid to be rendered again with appropriate column widths for the new grid width.



来源:https://stackoverflow.com/questions/17807490/how-to-launch-gridx-column-width-recalculation-after-the-grid-has-been-started-u

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!