0

My question is regarding generate xml ,

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.

Community
  • 1
  • 1
user590586
  • 2,960
  • 16
  • 63
  • 96

1 Answers1

1

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg: That work's great!! thank you! I have one more question about this issue , is it posiible to add attribute to the 'row' tag? and can I add another tag with custom data to each row tags? thank's. – user590586 Feb 03 '11 at 10:19
  • @Oleg: Is it possible to generate this xml when the row is in edit mode? – user590586 Feb 23 '11 at 10:51
  • @user590586: Yes, but you will don't export not yet saved editing values. It is by design so, because the user has the possibility to click "Esc" to go back to the original values. It you want have access to the current values from the editing cells you have to use jQuery to read direct from the `` elements the current values. – Oleg Feb 23 '11 at 11:01