gpt4 book ai didi

jquery - Slickgrid 列宽应根据最宽的行内容自动调整大小

转载 作者:行者123 更新时间:2023-11-30 23:51:08 25 4
gpt4 key购买 nike

在 Slickgrid 中,有什么方法可以根据最宽的行内容自动调整列宽吗?

在示例示例中,我可以看到列的值被硬编码为列字段 http://mleibman.github.com/SlickGrid/examples/example2-formatters.html

var columns = [
{id: "title", name: "Title", field: "title", width: 120, cssClass: "cell-title", formatter: formatter},
{id: "duration", name: "Duration", field: "duration"},
{id: "%", name: "% Complete", field: "percentComplete", width: 80, resizable: false, formatter: Slick.Formatters.PercentCompleteBar},
{id: "start", name: "Start", field: "start", minWidth: 60},
{id: "finish", name: "Finish", field: "finish", minWidth: 60},
{id: "effort-driven", name: "Effort Driven", sortable: false, width: 80, minWidth: 20, maxWidth: 80, cssClass: "cell-effort-driven", field: "effortDriven", formatter: Slick.Formatters.Checkmark}
];

最佳答案

您可以使用 forceFitColumns 选项,该选项将调整每列的大小以适应,但如果您的宽度不够宽,它会尝试根据您的宽度的最小值和最大值来适应,因此您可能需要添加 minWidthmaxWidth,以便您拥有更多控制权。

例如,列定义可能如下所示:

{id: "duration", name: "Duration", field: "duration", minWidth:50, width:100, maxWidth:120}

选项定义如下:

options = {
enableCellNavigation: true,
enableColumnReorder: false,
multiColumnSort: true,
asyncEditorLoading: true,
forceFitColumns: true // this one is important
};

关于jquery - Slickgrid 列宽应根据最宽的行内容自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15200574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com