简体   繁体   English

UI-Grid按其内容设置列的宽度

[英]UI-Grid Set columns width by their content

I recently started using ui-grid and I want that when the grid initializes, each column will have width according to its content. 我最近开始使用ui-grid,我希望在网格初始化时,每一列都将根据其内容具有宽度。

I know there is a function that does that in ui-grid when the user double-clicks a cell to resize (resizer.link.dblClickFn) but it doesn't take a column as a parameter, it takes an event of a column click. 我知道当用户双击要调整大小的单元格时,会在ui-grid中执行此功能(resizer.link.dblClickFn),但它不将列作为参数,而是需要单击列的事件。

Anyone has any experience with this? 有人对此有经验吗?

I was evetually able to solve it by manually calling the double click event on all the resizers : 我可以通过手动调用所有调整大小的双击事件来解决该问题:

    onRegisterApi: function (gridApi) {
        $scope.gridApi = gridApi;

        setTimeout(function () {
            var resizers = document.getElementsByClassName("ui-grid-column-resizer");

            for (var i = 0; i < resizers.length; i++) {
                var event = new MouseEvent('dblclick', {
                    'view': window,
                    'bubbles': true,
                    'cancelable': true
                });

                resizers[i].dispatchEvent(event);
            }
        }, 1);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM