2

好的,让我更清楚地解释我的情况:

当一个单元格被编辑时,它会变得“脏”,我通过 javascript 向单元格添加一个 CSS 类来以某种方式设置它的样式。

然后,如果用户对网格进行排序,样式就会丢失(我相信是因为所有行都被重新创建了),我需要一种方法在排序后将样式恢复到适当的单元格/行。

我试图做的是在 data[] 中添加一个名为“status”的条目,onCellChange 我遍历 data[] 并将 args.item.Id 与 data[] 中的相应条目匹配。

grid.onCellChange.subscribe(function (e, args) {
    var done = false;
    for (var i = 0; i < data.length && !done; i++) {
        if (data[i].id == args.item.id) {
            data[i].status = "dirty";
            done = true;
        }
    }
}

但是,onSort 我不确定如何将已排序的行与数据数组匹配。(因为我没有 args.item)我尝试使用选择器语句:$(".slick-row") 来重新设置正确单元格的样式,但我无法将行与它们在 data[] 中的条目相关联。

4

1 回答 1

3

1) There is no need to search for the item in your onCellChange handler - it is available at "args.item".

2) Sorting the "data" array will not wipe out your change to the item in #1.

3) You mention dynamically styling cells. I see no code for that. If your custom formatter is the piece of code that looks at "item.status" and renders it differently if it is dirty, then you don't have to do anything extra. Sorting the data and telling the grid to re-render will preserve the "dirty" cell styles.

于 2011-06-16T22:50:44.463 回答