背景的行号

时间:2013-11-08 10:51:27

标签: backgrid

如何将行号分配给backgrid的行而不将其定义为列之一? 我想从1开始分配行号;标题中有或没有文字

2 个答案:

答案 0 :(得分:1)

你可以这样做效率稍低:

var RowNumberCell = Backgrid.StringCell.extend({
  render: function () {
    return this.model.collection.indexOf(this.model) + 1;
  }
});

var columns = [{
  name: "",
  cell: RowNumberCell,
  editable: false,
  sortable: false
},
...
];

答案 1 :(得分:1)

我不得不对Y.H Wong的回答进行轻微编辑,因为我不断收到以下错误。

  

'Node':参数1不是'Node'类型

通过使用以下代码,我能够获得所需的行为,尽管使用相同的效率稍低的方法。

// Row Number Cell.
var RowNumberCell = Backgrid.StringCell.extend({
    render: function () {
        const number = this.model.collection.indexOf(this.model) + 1;
        this.$el.text(number);
        return this;
    }
});