【问题标题】:how to add hidden column in slickgrid如何在 slickgrid 中添加隐藏列
【发布时间】:2012-06-26 05:18:31
【问题描述】:

是否可以在 slickgrid 中设置隐藏列?隐藏列的意思是我想为每一行保存一些数据,但我不希望这些数据显示在网格上。

【问题讨论】:

  • 我把这个放在哪里?我认为这不是一个好方法。

标签: jquery slickgrid


【解决方案1】:

在 angular-slickgrid 版本中,您可以执行以下操作 1.在列定义中,包括所有列的 2. 在 Present 中,重新添加您想在网格中看到的列 ID。现在加载页面并查看列选择器菜单。你会很高兴看到所有的专栏。一些未经检查的

例如

    this.columnDefinitions = [
    { id: 'name', name: 'Name', field: 'name', filterable: true, sortable: true },
    { id: 'duration', name: 'Duration', field: 'duration', filterable: true,sortable: true },
    { id: 'complete', name: '% Complete', field: 'percentComplete', filterable:true,sortable: true }
    ];



this.gridOptions = {
      presets: {
        // the column position in the array is very important and represent
        // the position that will show in the grid
        columns: [
          { columnId: 'duration', width: 88, headerCssClass: 'customHeaderClass' },
          { columnId: 'complete' }
        ]
// name will be present in the menu but not on the grid

【讨论】:

    【解决方案2】:

    数据和网格中的列之间没有隐含的关系——两者完全独立存在。因此,您的数据可以包含比实际绑定到网格列更多的字段。

    例子:

    var grid;
    var columns = [
      {id: "title", name: "Title", field: "title"},
      {id: "duration", name: "Duration", field: "duration"},
      {id: "%", name: "% Complete", field: "percentComplete"},
      {id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
    ];
    
    var options = {
      enableCellNavigation: true,
      enableColumnReorder: false
    };
    
    $(function () {
      var data = [];
      for (var i = 0; i < 500; i++) {
        data[i] = {
          title: "Task " + i,
          duration: "5 days",
          percentComplete: Math.round(Math.random() * 100),
          start: "01/01/2009",
          finish: "01/05/2009",
          effortDriven: (i % 5 == 0)
        };
      }
    
      grid = new Slick.Grid("#myGrid", data, columns, options);
    })
    

    这里我的dataarray 包含字段startfinish,但我在创建columns 数组时选择排除它们。

    【讨论】:

    • 太棒了!我认为这会破坏 slickgrid。谢谢njr。
    • 这是正确的。但是在我的情况下,总共有 8 列,其中 4 列显示在网格中。使用复合编辑器时,如果未声明列,如何定义列编辑器?一个“可见”的列属性会非常好。
    • mleibman.github.io/SlickGrid/examples有复合和复合编辑器的示例
    【解决方案3】:

    我认为你可以通过使用grid.setColumns 来实现这一点——假设你在声明网格时设置了columns={id, a, b, c};初始化网格后,您可以调用grid.setColumns(newColumns) - 其中newColumns 是不包括id - newColumns={a, b, c} 的新列数组。

    此列仍然可以访问,并且与之关联的所有数据也应该可用。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2013-11-04
      • 2011-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多