Javascript 是否可以停止选择和/或突出显示 jqGrid 行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2148135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:57:49  来源:igfitidea点击:

Is it possible to Stop jqGrid row(s) from being selected and/or highlighted?

javascriptjqueryjqgridjquery-1.3.2

提问by Mike

I've looked at the documentationbut I've been unable to find an answer. Is there a way to prevent a row from being highlighted when selected? That or even a way to stop the row being selected at all. I like the "hoverrows: true" option, but ideally I would like to stop a row from being selected on-click.

我查看了文档,但一直找不到答案。有没有办法防止选中某行时突出显示?那甚至是一种完全停止选择行的方法。我喜欢“hoverrows:true”选项,但理想情况下,我想停止单击时选择一行。

Thanks,

谢谢,

Update:I've been able to "hackily" implement something which seems to be an interim fix. I don't really like it at all and would idealy like a better solution, if there is one...

更新:我已经能够“hackily”实现一些似乎是临时修复的东西。我根本不喜欢它,如果有的话,我希望有一个更好的解决方案......

I have found that if I pass the option

我发现如果我通过选项

onSelectRow: function(rowid, status) {
    $('#'+rowid).removeClass('ui-state-highlight');
}

when I instantiate the jqGrid, I can strip the highlight when it is added.

当我实例化 jqGrid 时,我可以在添加时去除高光。

Is there another, more ideal, way to do this?

还有另一种更理想的方法来做到这一点吗?

回答by Vinodh Ramasubramanian

Use the following code:

使用以下代码:

beforeSelectRow: function(rowid, e) {
    return false;
}

回答by eliland

If you, like me, have a gazillion jqGrids and don't want to override onSelectRow for every single one, here's a global version of Reigel's solution that worked nicely for me:

如果您像我一样拥有大量 jqGrid 并且不想为每一个都覆盖 onSelectRow,这里有一个 Reigel 解决方案的全球版本,对我来说效果很好:

jQuery.extend(jQuery.jgrid.defaults, {
    onSelectRow: function(rowid, e) {
        $('#'+rowid).parents('table').resetSelection();
    }
});

回答by Reigel

try:

尝试:

onSelectRow: function(rowid, status) {
    $("#grid_id").resetSelection(); //Resets (unselects) the selected row(s). Also works in multiselect mode.
}

you can read documentations here. Hope it helps you...

你可以在这里阅读文档。希望能帮到你...

回答by Peter Bailey

I suppose you could address this in the CSS directly. Just override the values for ui-state-highlight for your specific table

我想你可以直接在 CSS 中解决这个问题。只需覆盖特定表格的 ui-state-highlight 值

#table_id tr.ui-state-highlight {
  border: inherit !important;
  background: inherit !important;
  color: inherit !important;
}

#table_id tr.ui-state-highlight a {
  color: inherit !important;
}

#table_id tr.ui-state-highlight .ui-icon {
  background-image: inherit !important;
}

I used the value inheritjust as an example - you will likely need to copy some values from your theme.css to make this work.

inherit仅将值用作示例 - 您可能需要从 theme.css 中复制一些值才能完成此工作。

回答by Justin Levene

Yes, use the rowattr callback:

是的,使用 rowattr 回调:

rowattr: function (rowData,currentObj,rowId) {
    if (rowData.SomeField=="SomeValue") { 
        return {"class": "ui-state-disabled"};
    }
},

This also grays out the row and disables the selection.

这也会使行变灰并禁用选择。