【问题标题】:SlickGrid Column Picker: Setting the default columns to display from a larger listSlickGrid 列选择器:设置默认列以从更大的列表中显示
【发布时间】:2013-01-04 10:03:42
【问题描述】:

我目前正在使用 SlickGrid 并允许用户使用 ColumnPicker 选择要显示的列。

按照http://mleibman.github.com/SlickGrid/examples/example4-model.html 的示例,我已经能够让它很好地工作。

我不确定的下一步是是否可以选择在第一次渲染时显示的默认列列表。

例如,假设我有一个包含 5 列的数组,声明如下:

{
                    name: "Name"
                    field: "Name"
                    id: "Name" 
                    sortable: true
                    minWidth: 120
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Address"
                    field: "Address" 
                    id: "Address"
                    sortable: true
                    minWidth: 175
                    editor: Slick.Editors.Text
                },
                {
                    name: "Town"
                    field: "Town"
                    id: "Town"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Country"
                    field: "Country"
                    id: "Country"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }, 
                {
                    name: "Network"
                    field: "Network"
                    id: "Network"
                    sortable: true
                    minWidth: 80
                    editor: Slick.Editors.Text
                }

此时所有这些列都将显示,并且可以选择隐藏在 ColumnPicker 中。我正在寻找的功能是,例如,说我只希望显示列名称、地址和网络,但仍然让其他列作为 ColumnPicker 中的选项。

这是到位还是有实现此目的的可用方法?

【问题讨论】:

    标签: javascript slickgrid


    【解决方案1】:

    对于任何可能遇到此问题的人,我找到了一个可行但可能不是最好的解决方案。

    它本质上是使用 2 个单独的数组,1 个保存要渲染的默认列,另一个保存您可以选择的所有列的名称,包括默认列数组。

    渲染时,我用默认列的数组实例化我的网格:

    @Grid = new Slick.Grid(@ElementId, @Data, @DefaultColumns, @GridOptions)

    然后在设置列选择器时,使用所有列的数组:

    columnpicker = new Slick.Controls.ColumnPicker(@Columns, @Grid, @GridOptions)

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 1970-01-01
      • 2017-03-31
      • 2015-02-10
      • 2017-12-08
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多