清除按钮上的多个单元格突出显示单击jqgrid

时间:2014-11-18 12:44:41

标签: jqgrid

我有jqgrid,其中我选择了多个单元格(Ctrl键),这是黄色突出显示。

现在点击按钮我必须清除突出显示的所有单元格。但是如果选择了一行,它应该是相同的。只需删除单元格高亮显示。

任何可能性?

1 个答案:

答案 0 :(得分:1)

对您之前的问题的答案似乎是一个小修改。如果mySelection参数包含有关所选单元格的信息,则可以取消选择以下事件处理程序中的单元格:

$("#clearCellSelection").button().click(function () {
    var key, item, $td, rows = $grid[0].rows, p = $grid.jqGrid("getGridParam"),
        mySelection = p.mySelection,
        idPrefix = p.idPrefix;

    // click without Ctrl key pressed
    // we need unselect all
    for (key in mySelection) {
        if (mySelection.hasOwnProperty(key)) {
            item = mySelection[key];
            $td = $(rows.namedItem(idPrefix + item.id).cells[item.indexOfColumn]);
            $td.removeClass("ui-state-highlight").removeAttr("aria-selected");
        }
    }
    p.mySelection = {};
});

相应的修改演示版为here

如果网格包含sortable: true选项或columnChooser允许用户更改列的顺序,则应该小心。在这种情况下,不能使用所选单元信息的indexOfColumn属性。而不是那个必须使用colName属性,并在colName中找到名称为colModel的列的索引。应该使用索引而不是indexOfColumn