How should I send userdata to jqGrid?
Question
ok, here is the thing ... I've this jqGrid and what I need is to sumarize showed data. This jqGrid has definitions as shown bellow
jQuery("#myGrid").jqGrid
{
url:'/loadGrid.php?q=2',
datatype: "xml",
colNames:[...],
colModel:[...],
// some other params.
footerrow : true,
**userDataOnFooter : true,** // it should show footer's custom information.
altRows : true
}).navGrid('#pagerGrid',{add:false,edit:false,del:false, search:false});
and loadGrid.php has the next structure shown bellow
$page = $_GET['page']; // get the requested page
$limit = $_GET['rows']; // get how many rows we want to have into the grid
$sidx = $_GET['sidx']; // get index row - i.e. user click to sort
$sord = $_GET['sord']; // get the direction
// here goes connextion to database and data collection
...
//
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{
header("Content-type: application/xhtml+xml;charset=utf-8");
}
else
{
header("Content-type: text/xml;charset=utf-8");
}
$et = ">";
echo "<?xml version='1.0' encoding='utf-8'?$et\n";
echo "<rows>";
echo "<page>$current</page>";
echo "<total>$total</total>";
echo "<records>$records</records>";
// and data population
foreach( $data as $key => $value )
{
$ff = $value['field_1'];
echo "<row id='". $ff."'>";
// $ff = $value['field_1'];
echo "<cell> <![CDATA[" . $ff . "]]></cell>";
$ff = $value['field_2'];
echo "<cell> <![CDATA[" . $ff . "]]></cell>";
$ff = $value['field_3'];
echo "<cell> <![CDATA[" . $ff . "]]></cell>";
// ... and so on whith all column definitions.
echo "</row>";
}
echo "</rows>";
This works but the problems becomes when show the grid. In the footer of the grid I only see an empty row. If I put some sumarized data and try to send to the page it doesn't show anything. So, What I need to know is how should I pass userdata for the page to read it.
I'd already read information from jqGrid whiki and said something like "userData: This array contain custom information from the request. Can be used at any time." but I cann't figure how to pass this information to #myGrid. Does somebody has any idea about it? Any help will strongly appreciated.
Solution
Format of user data in XML can looks a little strange at the first look, but it is clear documented here. You should add some XML elements in the form
...
<page>1</page>
<userdata name="gridColumName1">value1 in the summary</userdata>
<userdata name="gridColumName2">value2 in the summary</userdata>
...
You should use the same column names ('gridColumName1', 'gridColumName2') like you as defined in the name
property of columns definitions in the colModel
.