本文介绍了根据单元格值在jqGrid中选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

colModel: [
            { name: 'Id', index: 'Id', hidden: true, search: false },
            { name: 'Name', index: 'Name', hidden: true, search: false },
          ]

就像setSelection方法允许基于行号在jqGrid中选择行一样,是否有可能类似地基于单元格值之一选择行.

Just as the setSelection method allows selection of a row in jqGrid based on the row number, is it possible to similarly select a row based on one of the cell values.

例如在上面的colModel中,可以选择具有某个"Id"或"Name"值的行...假设这些值对于每一行都是唯一的.

For e.g. in the colModel above, is it possible to select a row having a certain 'Id' or 'Name' value...assuming that these values are unique for each row.

推荐答案

在jqGrid的loadComplete:部分中,您可以遍历每一行并测试所需的值.如果找到该值,请选择该行.

In the loadComplete: portion of your jqGrid you could iterate over each row and test for the value you are looking for. If the value is found, select the row.

Ex

loadComplete: function () {
    var rowIds = $(this).jqGrid('getDataIDs');

    for (i = 1; i <= rowIds.length; i++) {
        rowData = $(this).jqGrid('getRowData', i);

        if (rowData['Id'] == idSearchValue ) {
           $(this).jqGrid('setSelection',i);
        } //if

    } //for
...

也将有rowattr:,但是我似乎找不到在哪里可以获取当前行的rowID. Oleg可能会看到这种情况并做出回应,这也是他对jqGrid的补充,但是我的测试并没有带来任何运气,也没有阅读将当前rowId传递给setSelection方法的位置.

There would also be the rowattr: but I can't seem to find where you can get the rowID of the current row. Oleg might see this and respond as well as it was his addition to jqGrid but I didn't have any luck with my testing or read though of where you would get the current rowId to pass to the setSelection method.

这篇关于根据单元格值在jqGrid中选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 04:21