以编程方式选择jqGrid中的所有行? [英] Programmatically select all rows in a jqGrid?

查看:78
本文介绍了以编程方式选择jqGrid中的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以编程方式选择jqGrid中设置为multiselect的所有行的最佳方法是什么?

What is the best way to programmatically select all rows in a jqGrid that is set to multiselect?

代码可以一次一个地遍历所有行并选择每一行,但是不检查网格标题中的复选框。我正在考虑只触发标题行复选框的单击事件,但这会假设底层的jqGrid实现。必须有更好的方法......

The code could loop through all of the rows one-at-a-time and select each one, but then the checkbox in the grid header is not checked. I was thinking about just triggering the header row checkbox's clicked event, but that would make assumptions about the underlying jqGrid implementation. There must be a better way...

提前致谢!

推荐答案

如果通过手动单击每个行来选择多选jqGrid中的所有行,则不会检查标题中的复选框,因此当您以编程方式执行时,我不一定会发生这种情况(如果您对每一行使用setSelected(rowid,true),它相当于点击每一行,因为true参数表示应为每一行触发点击事件。

If you select all of the rows in a multiselect jqGrid by clicking on each one manually, the checkbox in the header doesn't get checked, so I wouldn't necessarily expect it to happen when you do it programmatically (if you use setSelected(rowid, true) for each row, it's the equivalent of clicking on each, as the "true" parameter indicates that the clicked event should be fired for each one).

所以事实上,如果你想要检查所有这些并且想要检查标题中的复选框,触发点击的事件可能是你最好的选择。如果您深入了解源代码并查看单击复选框时发生的情况,实际上只是循环遍历所有行并将每个行设置为选中,所以我认为您不会做得更好。

So in fact, if you want all of them to get checked AND want the checkbox in the header to be checked, triggering the clicked event may be your best bet. If you dig into the source code and look at what happens when you click the checkbox, it is in fact just looping through all of the rows and setting each as selected, so I don't think you're going to do a lot better.

这篇关于以编程方式选择jqGrid中的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆