XML String

The xmlstring option has similar features to the xml option. The only difference is that the data is passed as string. In this case we need to have a valid xml data string. To do that we can use a datastr option. This example shows how to do that.

<script> var mystr = "<?xml version='1.0' encoding='utf-8'?> <invoices> <rows> <row> <cell>data1</cell> <cell>data2</cell> <cell>data3</cell> <cell>data4</cell> <cell>data5</cell> <cell>data6</cell> </row> </rows> </invoices>"; jQuery(document).ready(function(){ jQuery("#list").jqGrid({ datatype: 'xmlstring', datastr : mystr, colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'], colModel :[ {name:'invid', index:'invid', width:55, sorttype:'int'}, {name:'invdate', index:'invdate', width:90, sorttype:'date', datefmt:'Y-m-d'}, {name:'amount', index:'amount', width:80, align:'right', sorttype:'float'}, {name:'tax', index:'tax', width:80, align:'right', sorttype:'float'}, {name:'total', index:'total', width:80, align:'right', sorttype:'float'}, {name:'note', index:'note', width:150, sortable:false} ], pager: jQuery('#pager'), rowNum:10, viewrecords: true, imgpath: 'themes/basic/images', caption: 'My first grid' }); }); </script>

As you can see, this example introduces another option in colModel: sorttype. This option describes how a particular column is to be sorted, because when using xmlstring as the source for the grid, jqGrid uses client-side sorting.


  Last Updated: 7/10/2008 | © Tony's jqGrid - a jQuery Plugin, 2010