jqgrid generating xml only for selected row
My question is regarding generate 开发者_如何学Goxml ,
Is there a way to get only the selected rows inside of the xml and not all of the grid's rows??
Thank's In Advance.
You can do following
var selRowId = grid.jqGrid ('getGridParam', 'selrow');
if (selRowId) {
var dataFromGrid = {row: grid.jqGrid ('getRowData', selRowId) };
var xmldata='<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n<rows>\n'+
xmlJsonClass.json2xml (dataFromGrid, '\t') + '</rows>';
alert(xmldata);
}
see here the modified demo.
UPDATED: If you need to add additional attributes to the <row>
elements you should add properties started with '@'.
var selRowId = grid.jqGrid ('getGridParam', 'selrow');
if (selRowId) {
var rowData = grid.jqGrid ('getRowData', selRowId);
rowData["@foo"] = "bar";
var xmldata='<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n<rows>\n'+
xmlJsonClass.json2xml ({row: rowData}, '\t') + '</rows>';
alert(xmldata);
}
See the demo.
精彩评论