JQgrid - Enter row number instead of ID
I am creating a JQGrid from a database table that does not contain the primary key of a single field. Therefore, the field I provide as id is not unique and the same exists across multiple lines.
Because of this, when passing a data reference using ondblClickRow to a function external to the grid, I need to use a router, not an ID.
To test, I am using ondblClickRow: function(id){alert($("#grid1").getInd('rowid'));},
and I have to get and warn the line number, except it doesn't work.
I am doing documentation and do not understand what I am doing wrong ...
Any help would be greatly appreciated!
Thanks in advance, Mario.
Bellow is my full mesh:
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
});
a source to share
The answer to your main question gives you great_llama, but it seems to me that you have little understanding of id
how the XML input used by jqGrid. The default xmlReader
is id: "[id]"
. So you just remove id: "DEVICE_ID"
from the definition xmlReader
and put the attribute in your data 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>";
So your master data that your server is sending might have double lines, but if you just add an attribute id
that might be a row count, you might be able to solve your problem. The attribute value id
must not be a number, you can use any string. If the nature of your data allows it, you can create a unique one id
as a string composed of your other data.
a source to share