[英]Clear previous selection only if checkbox is not clicked in jQgrid?
I have a grid setup with multiselect: true
because I need to be able to delete more than one row at the same time. 我有一个带有
multiselect: true
的网格设置multiselect: true
因为我需要能够同时删除多个行。 On the onSelectRow
event I am loading some data based on the ID
and displaying it to the end user. 在
onSelectRow
事件上,我正在基于ID
加载一些数据并将其显示给最终用户。 So far so good. 到现在为止还挺好。
This is the example where everything works fine, the data for ID=219109
is being displayed: 这是一切正常的示例,正在显示
ID=219109
的数据:
Now look at the following example: 现在看下面的例子:
In the example above the first row still highlighted and then I clicked a second one. 在上面的示例中,第一行仍突出显示,然后单击第二行。 Because of
multiselect
is enabled I was able to select both at the same time. 由于启用了
multiselect
因此我能够同时选择两者。 The onSelectRow
event still working properly which means is loading the data for the ID=282006
but visually it could be confusing for the end user. onSelectRow
事件仍然可以正常工作,这意味着正在加载ID=282006
的数据,但从视觉上看,这可能会使最终用户感到困惑。
What I want to do is to reset the previous selected rows and just highlight the last one I have clicked. 我想做的是重置先前选择的行,然后仅突出显示我单击的最后一行。
For example using the same images: 例如,使用相同的图像:
ID=219109
: highlight and select this row ID=219109
:突出显示并选择此行 ID=282006
: clear the grid and highlight this row ID=282006
:清除网格并突出显示此行 However this should only happen when I click in any other place than the checkbox. 但是,仅当我单击复选框以外的任何其他位置时,才应该发生这种情况。
In the image above if I click on any column rather than the first one (the one having the checkbox) I should be able to clear the grid selection and choose the last one but if I click on the checkbox it does not matter because is the only way to delete more than one at the time. 在上图中,如果我单击任何列而不是第一列(具有复选框的列),我应该能够清除网格选择并选择最后一个列,但是如果我单击该复选框,则没有关系,因为唯一一次删除多个的方法。
I have tried the following: 我尝试了以下方法:
onSelectRow: function () {
var rowid = $(this).jqGrid('getGridParam', 'selrow');
$(this).jqGrid("resetSelection");
$(this).jqGrid("setSelection", rowid);
}
But it's not working since the behavior is not consistent. 但由于行为不一致,因此无法正常工作。 You can check the demo here .
您可以在此处查看演示。
Any ideas in how to achieve this? 关于如何实现这一目标的任何想法?
It seems to me that you need just add the option 在我看来,您只需要添加选项
multiboxonly: true
and remove your current onSelectRow
code. 并删除当前的
onSelectRow
代码。 See https://jsfiddle.net/OlegKi/949pLpfv/3/ . 参见https://jsfiddle.net/OlegKi/949pLpfv/3/ 。 If the user clicks multiple times on checkbox the rows will be selected.
如果用户多次单击复选框,则将选择行。 The click on another part of the row will deselect all previously selected rows and select only the clicked row.
单击该行的另一部分将取消选择所有先前选择的行,并仅选择单击的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.