jqGrid的选择问题与重复列 [英] Jqgrid selection issue with duplicates columns

查看:1860
本文介绍了jqGrid的选择问题与重复列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米面临的一个问题与jqGrid的行选择。我在电网重复行。
每当我选择重复或选择重复行的第一条记录。

I m facing a issue in Jqgrid with row selection. I have duplicated rows in the grid. whenever i select the duplicate or it select the first record of that duplicate row.

推荐答案

这对许多人谁开始使用jqGrid的通病。如果您填写的网格具有行 ID重复这样奇怪的选择行为存在。所以的它来了解如何从你输入ID将由jqGrid的

It's common problem for many people who start to use jqGrid. Such strange selection behavior exist if you fill the grid with rows having id duplicates. So it's extremely important to understand how the ids from your input will be used by jqGrid.

jqGrid的内部使用HTML标记来显示网格。它采用<表> < TBODY> (该表的主体 - 没有列标题) < TR> (表行)和< TD> (表的表)的任何网格。下面的HTML片段可以重新present网格例如:

jqGrid use internally HTML markup to display the grid. It uses <table>, <tbody> (the body of the table - has no column headers), <tr> (row of the table) and <td> (table of the table) for any grid. The HTML fragment below could represent your grid for example

<table>
    <tbody>
        <tr><td>16</td><td>A11</td><td>Add</td></tr>
        <tr><td>1</td><td>Chart</td><td>Edit</td></tr>
        <tr><td>1</td><td>Chart</td><td>Delete</td></tr>
        <tr><td>1</td><td>Chart</td><td>View</td></tr>
        <tr><td>15</td><td>Manage</td><td>Edit</td></tr>
        <tr><td>16</td><td>A11</td><td>View</td></tr>
        <tr><td>15</td><td>Manage</td><td>Delete</td></tr>
    </tbody>
</table>

jqGrid的的设计是为了让人们可以有网格的快速访问任何行的。为了实现快速门禁一体需分配给每个&LT; TR&GT; (表行)的唯一ID 即可。你会发现在最方法或的事件的使用jqGrid的。在设置表的行的行的标识应的确定的行。在这种情况下电网就会像下面

The design of jqGrid is so that one can have quick access to any row of the grid. To implement the quick access one need assign to every <tr> (table row) an unique id. You will find rowid parameters in the most methods or events used by jqGrid. The id of the row should identify the row in the set of the rows of the table. In the case the grid will be like the following

<table>
    <tbody>
        <tr id="a"><td>16</td><td>A11</td><td>Add</td></tr>
        <tr id="b"><td>1</td><td>Chart</td><td>Edit</td></tr>
        <tr id="c"><td>1</td><td>Chart</td><td>Delete</td></tr>
        <tr id="abc"><td>1</td><td>Chart</td><td>View</td></tr>
        <tr id="1"><td>15</td><td>Manage</td><td>Edit</td></tr>
        <tr id="2"><td>16</td><td>A11</td><td>View</td></tr>
        <tr id="35"><td>15</td><td>Manage</td><td>Delete</td></tr>
    </tbody>
</table>

根据HTML规范的任何HTML元素的ID的必须在页面上唯一的。如果分配重复的ID对行喜欢这里例如:

According to the HTML specification the id of any HTML element must be unique on the page. If you do assign duplicate ids to the rows like here for example

<table>
    <tbody>
        <tr id="16"><td>16</td><td>A11</td><td>Add</td></tr>
        <tr id="1"><td>1</td><td>Chart</td><td>Edit</td></tr>
        <tr id="1"><td>1</td><td>Chart</td><td>Delete</td></tr>
        <tr id="1"><td>1</td><td>Chart</td><td>View</td></tr>
        <tr id="15"><td>15</td><td>Manage</td><td>Edit</td></tr>
        <tr id="16"><td>16</td><td>A11</td><td>View</td></tr>
        <tr id="15"><td>15</td><td>Manage</td><td>Delete</td></tr>
    </tbody>
</table>

表可以仍然显示在大多数web浏览器,但与电网工作可能是非常有问题的。例如,如果你选择这样网格的最后一行相应的jqGrid code会发现15作为当前行的id,它会使用 $(#15)。addClass( UI状态高亮)来凸显当前行。取而代之的是,code将选择(添加类UI状态高亮)只的第一行它具有ID =15。

the table could be still displayed in the most web browsers, but the working with the grid could be really problematic. For example if you select the last row of such grid the corresponding jqGrid code will find out 15 as the id of the current row and it will use $("#15").addClass("ui-state-highlight") to highlight the current row. Instead of that the code will select (add the class "ui-state-highlight") only to the first row which has the id="15".

所以,你应该非常小心,如果您填写用作输入的jqGrid的JSON数据。下列数据
 例如可以重新present网格包含以下内容:

So you should be very careful if you fill your JSON data used as the jqGrid input. The following data for example could represent the grid contain:

{
    "total": 1,
    "page": 1,
    "records": 7,
    "rows": [
        { "id": "16", "cell": ["16", "A11", "Add"] },
        { "id": "1", "cell": ["1", "Chart", "Add"] },
        { "id": "1", "cell": ["1", "Chart", "Delete"] },
        { "id": "1", "cell": ["1", "Chart", "View"] },
        { "id": "15", "cell": ["15", "Manage", "Delete"] },
        { "id": "16", "cell": ["16", "A11", "View"] },
        { "id": "15", "cell": ["15", "Manage", "Edit"] }
    ]
}

JSON数据可以被固定在

The JSON data could be fixed to

{
    "total": 1,
    "page": 1,
    "records": 7,
    "rows": [
        { "id": "1", "cell": ["16", "A11", "Add"] },
        { "id": "2", "cell": ["1", "Chart", "Add"] },
        { "id": "3", "cell": ["1", "Chart", "Delete"] },
        { "id": "4", "cell": ["1", "Chart", "View"] },
        { "id": "5", "cell": ["15", "Manage", "Delete"] },
        { "id": "6", "cell": ["16", "A11", "View"] },
        { "id": "7", "cell": ["15", "Manage", "Edit"] }
    ]
}

{
    "total": 1,
    "page": 1,
    "records": 7,
    "rows": [
        { "id": "16_Add", "cell": ["16", "A11", "Add"] },
        { "id": "1_Add", "cell": ["1", "Chart", "Add"] },
        { "id": "1_Delete", "cell": ["1", "Chart", "Delete"] },
        { "id": "1_View", "cell": ["1", "Chart", "View"] },
        { "id": "15_Delete", "cell": ["15", "Manage", "Delete"] },
        { "id": "16_View", "cell": ["16", "A11", "View"] },
        { "id": "15_Edit", "cell": ["15", "Manage", "Edit"] }
    ]
}

例如。那么世界(含电网)将成为确定。

for example. Then the world (inclusive the grid) will become OK.

这篇关于jqGrid的选择问题与重复列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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