【问题标题】:How to hide backgrid column?如何隐藏 backgrid 列?
【发布时间】:2014-06-01 17:33:08
【问题描述】:

朋友们好。我在我的项目中使用backgrid。我想从backgrid 隐藏Id 列。这是我的代码。

var columns = [
{ name: "id", label: "Id", cell: "integer", editable: false },
{ name: "payment_date", label: "Payment Date", cell: "date" ,editable: false },
{ name: "number_of_task", label: "Total Task", cell: "integer" ,editable: false },
{ name: "amount", label: "Amount", cell: "integer" ,editable: false }
];

【问题讨论】:

    标签: backgrid


    【解决方案1】:

    只需删除列定义。您不需要为数据中的每个地址定义列;您只需要您希望在表中可见的属性的列定义。

    var columns = [
        { name: "payment_date", label: "Payment Date", cell: "date" ,editable: false },
        { name: "number_of_task", label: "Total Task", cell: "integer" ,editable: false },
        { name: "amount", label: "Amount", cell: "integer" ,editable: false }];
    

    【讨论】:

    • 感谢您的回复。我需要将 ID 列作为隐藏字段。所以我需要隐藏它而不是删除。任何建议都可能会有所帮助。谢谢
    • 只是好奇,当您的意思是隐藏时,您的意思是可以将其切换为可见或不可见吗?在这种情况下,你是对的,列定义是必要的。
    • 实际上 Id 字段是我执行更新/删除操作的必填字段,所以我只想隐藏/不可见它,包括 Id tr 及其所有 tds。
    • 问题由 Mark 添加一个 renderable: false 属性来解决。在此处查看可渲染wyuenho.github.io/backgrid/api/index.html#!/api/Backgrid.Column
    • 我需要隐藏一列,以便我仍然可以使用它来对表格进行排序。
    【解决方案2】:

    添加renderable: false 属性。在此处查看可渲染http://wyuenho.github.io/backgrid/api/index.html#!/api/Backgrid.Column

    【讨论】:

      【解决方案3】:

      属性 renderable:false 对我不起作用,因此在下面用作解决方法

      var HideCell = Backgrid.HideCell = Backgrid.Cell.extend({
          /** @property */
          className: "hide-cell",
      
          initialize: function () {
              Backgrid.Cell.prototype.initialize.apply(this, arguments);
          },
      
          render: function () {
              this.$el.hide();
              return this;
          }
      });
      

      在列中用作单元格“隐藏”

      var columns = [
          { name: "id", label: "Id", cell: HideCell, editable: false }
      ];
      

      【讨论】:

        猜你喜欢
        • 2013-05-19
        • 2012-02-08
        • 1970-01-01
        • 2021-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多