JQgrid - 获取行号而不是 ID
我正在从不包含单个字段主键的数据库表创建 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为您可以使用 getInd() 方法,如下所示:
http://www.trirand。 com/jqgridwiki/doku.php?id=wiki:方法
I think you can use the getInd() method, like this:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
您要查找的内容已传递给事件,您只需在函数声明中包含更多可用参数即可:
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:
你的主要问题的答案给了你great_llama,但在我看来,你有点误解
id
作为jqGrid使用的XML输入。默认xmlReader
具有id:“[id]”
。 ,您只需从xmlReader
的定义中删除id: "DEVICE_ID"
并将id
属性放入您的数据中:因此 服务器可以有双行,但是如果您只需添加 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. DefaultxmlReader
hasid: "[id]"
. So you just removeid: "DEVICE_ID"
from the definition ofxmlReader
and placeid
attribute in your data: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 ofid
attribute must not be a number, you can use any string instead. If the nature of your data allow this, you can produce an uniqueid
as a string composed from your other data.最近我有同样的需求,即通过行号而不是行 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);
我这样做是这样的:
I make it like this: