JQgrid - 获取行号而不是 ID

发布于 2024-08-31 12:20:00 字数 1676 浏览 8 评论 0原文

我正在从不包含单个字段主键的数据库表创建 JQGrid。 因此,我提供的 id 字段不是唯一的,并且同一字段存在于多行中。

因此,当使用 ondblClickRow 将数据引用传递给网格外部的函数时,我需要使用行号而不是 id。

为了进行测试,我正在使用 ondblClickRow: function(id){alert($("#grid1").getInd('rowid'));}, ,我应该得到并发出警报行号,但它不起作用。

我已经阅读了文档,无法理解我做错了什么......

任何帮助将不胜感激!

提前致谢, 马里奥。

以下是我的完整网格:

jQuery(document).ready(function(){
var mygrid = jQuery("#grid1").jqGrid({
    datatype: 'xmlstring',
    datastr : grid1RsXML,
    width: 1024,
    height: 500,
    colNames:['DEVICE_ID','JOB_SIZE_IN_BYTES', 'USER_NAME','HOST_NAME','DAY_OF_WEEK','JOB_ID'],
    colModel:[ 
                {name:'DEVICE_ID',index:'DEVICE_ID', width:55, sortable:true},
                {name:'JOB_SIZE_IN_BYTES',index:'JOB_SIZE_IN_BYTES', width:40, sortable:true},
                {name:'USER_NAME',index:'USER_NAME', width:60, sortable:true},
                {name:'HOST_NAME',index:'HOST_NAME', width:50,align:"right", sortable:true},
                {name:'DAY_OF_WEEK',index:'DAY_OF_WEEK', width:10, sortable:true},
                {name:'JOB_ID',index:'JOB_ID', width:30, sortable:true}

             ],
    rowNum:1000,
    autowidth: true, 
    //rowList:[10,20,30],
    rowList:[1],
    pager: '#grid1Pager',
    sortname: 'DEVICE_ID',
    viewrecords: true,
    rownumbers: true,
    sortorder: "desc",
    sortable: true,
    gridview : true,
    xmlReader: { root : "recordset", row: "record", repeatitems: false, id: "DEVICE_ID" },
    caption:"All Jobs - Double Click for detailed history",
    ondblClickRow: function(id){alert($("#grid1").getInd('rowid'));}, 
    toolbar: [true,"top"],
    url: grid1RsXML
});

I am creating a JQGrid from a database table that does not contain a single field primary key.
Therefore, the field i am supplying as id is not unique and the same one exists in several rows.

Because of this, when passing a reference to the data with ondblClickRow to a function external to the grid i need to use the rownumber and not the id.

To test, I'm using ondblClickRow: function(id){alert($("#grid1").getInd('rowid'));}, , and i should be getting and alert with the row number, except that it isn't working.

I've been over the documentation and can't understand what i am doing wrong...

Any help would be greatly appreciated!

Thanks in advance,
Mario.

Bellow is my full grid:

jQuery(document).ready(function(){
var mygrid = jQuery("#grid1").jqGrid({
    datatype: 'xmlstring',
    datastr : grid1RsXML,
    width: 1024,
    height: 500,
    colNames:['DEVICE_ID','JOB_SIZE_IN_BYTES', 'USER_NAME','HOST_NAME','DAY_OF_WEEK','JOB_ID'],
    colModel:[ 
                {name:'DEVICE_ID',index:'DEVICE_ID', width:55, sortable:true},
                {name:'JOB_SIZE_IN_BYTES',index:'JOB_SIZE_IN_BYTES', width:40, sortable:true},
                {name:'USER_NAME',index:'USER_NAME', width:60, sortable:true},
                {name:'HOST_NAME',index:'HOST_NAME', width:50,align:"right", sortable:true},
                {name:'DAY_OF_WEEK',index:'DAY_OF_WEEK', width:10, sortable:true},
                {name:'JOB_ID',index:'JOB_ID', width:30, sortable:true}

             ],
    rowNum:1000,
    autowidth: true, 
    //rowList:[10,20,30],
    rowList:[1],
    pager: '#grid1Pager',
    sortname: 'DEVICE_ID',
    viewrecords: true,
    rownumbers: true,
    sortorder: "desc",
    sortable: true,
    gridview : true,
    xmlReader: { root : "recordset", row: "record", repeatitems: false, id: "DEVICE_ID" },
    caption:"All Jobs - Double Click for detailed history",
    ondblClickRow: function(id){alert($("#grid1").getInd('rowid'));}, 
    toolbar: [true,"top"],
    url: grid1RsXML
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我的鱼塘能养鲲 2024-09-07 12:20:00

我认为您可以使用 getInd() 方法,如下所示:

var sel_id = $grid.getGridParam('selrow');
var index = $grid1.jqGrid('getInd',sel_id); // counting from 1

http://www.trirand。 com/jqgridwiki/doku.php?id=wiki:方法

I think you can use the getInd() method, like this:

var sel_id = $grid.getGridParam('selrow');
var index = $grid1.jqGrid('getInd',sel_id); // counting from 1

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

赠我空喜 2024-09-07 12:20:00

您要查找的内容已传递给事件,您只需在函数声明中包含更多可用参数即可:

ondblClickRow: function(id, iRow, iCol, e) {
    alert(iRow);
},

What you're looking for is already passed to the event, you just need to include more of the available parameters in your function declaration:

ondblClickRow: function(id, iRow, iCol, e) {
    alert(iRow);
},
埋葬我深情 2024-09-07 12:20:00

你的主要问题的答案给了你great_llama,但在我看来,你有点误解id作为jqGrid使用的XML输入。默认 xmlReader 具有 id:“[id]”。 ,您只需从 xmlReader 的定义中删除 id: "DEVICE_ID" 并将 id 属性放入您的数据中:

var grid1RsXML = "<?xml version='1.0' encoding='utf-8'?>"+
  "<recordset>"+
      "<rows>"+
          "<record id='1'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
          "<record id='2'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
          "<record id='3'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
      "</rows>"+
  "</recordset>";

因此 服务器可以有双行,但是如果您只需添加 id 属性(可以是行计数器),您就可以解决您的问题。 id 属性的值不能是数字,可以使用任何字符串。如果数据的性质允许这样做,您可以生成一个唯一的 id 作为由其他数据组成的字符串。

The answer of your main question gives you great_llama, but it seams to me, that you a little misunderstand id as a XML input used by jqGrid. Default xmlReader has id: "[id]". So you just remove id: "DEVICE_ID" from the definition of xmlReader and place id attribute in your data:

var grid1RsXML = "<?xml version='1.0' encoding='utf-8'?>"+
  "<recordset>"+
      "<rows>"+
          "<record id='1'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
          "<record id='2'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
          "<record id='3'>"+
              "<DEVICE_ID>data1</DEVICE_ID>"+
              "<JOB_SIZE_IN_BYTES>data2</JOB_SIZE_IN_BYTES>"+
              "<USER_NAME>data3</USER_NAME>"+
              "<HOST_NAME>data4</HOST_NAME>"+
              "<DAY_OF_WEEK>data5</DAY_OF_WEEK>"+
              "<JOB_ID>data6</JOB_ID>"+
          "</record>"+
      "</rows>"+
  "</recordset>";

So your main data which send your server could have double rows, but if you just add id attribute which can be a row counter you can solve your problem. The value of id attribute must not be a number, you can use any string instead. If the nature of your data allow this, you can produce an unique id as a string composed from your other data.

过度放纵 2024-09-07 12:20:00

最近我有同样的需求,即通过行号而不是行 ID 访问行数据。我没有任何行 ID。下面的代码对我有用。注意:行数从 1 开始。

var rowNum=$("#grid1").getGridParam("selarrrow");
$("#grid1").getRowData(rowNum);

Recently I had same requirement, i.e to access the row data by row number rather than the row id. I don't have any row id. Below code works for me. NOTE: The row count starts from 1.

var rowNum=$("#grid1").getGridParam("selarrrow");
$("#grid1").getRowData(rowNum);

陈年往事 2024-09-07 12:20:00

我这样做是这样的:

ondblClickRow:function(rowid,iRow,iCol,e){var curPage =$("#gridTable").getGridParam("page");//current page var pageSize = $("#gridTable").getGridParam("rowNum");//records per pagevar count = parseInt((curPage-1)*pageSize) + parseInt(rowid);}

I make it like this:

ondblClickRow:function(rowid,iRow,iCol,e){var curPage =$("#gridTable").getGridParam("page");//current page var pageSize = $("#gridTable").getGridParam("rowNum");//records per pagevar count = parseInt((curPage-1)*pageSize) + parseInt(rowid);}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文