DIR : /home/kozerus/public_html/ko_center/js/jqgrid_demo35/loadcml.html

/home/kozerus/public_html/ko_center/js/jqgrid_demo35

<div style="font-size:12px;">
    This example demonstrates two new fetures in jqGrid <br>
    1. loadComplete() callback - this function is executed immediately after data is loaded.<br>
    This way we can make some changes depending on the needs.<br>
    2. New method getDataIDs() - returns the id's of currently loaded data.<br>
    This method can be used in combination with loadComplete callback.
</div>
<br />
<table id="list15" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager15" class="scroll" style="text-align:center;"></div>
<a href="javascript:void(0)" id="sids">Get Grid id's</a><br/>
<script src="loadcml.js" type="text/javascript"> </script>
<br />
<div style="font-size:12px;">
<b> HTML </b>
<XMP>
...
<table id="list15" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pager15" class="scroll" style="text-align:center;"></div>
<a href="javascript:void(0)" id="sids">Get Grid id's</a><br/>

</XMP>    
<b>Java Scrpt code</b>
<XMP>
...
jQuery("#list15").jqGrid({        
   	url:'server.php?q=2&nd='+new Date().getTime(),
	datatype: "json",
   	colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
   	colModel:[
   		{name:'id',index:'id', width:55},
   		{name:'invdate',index:'invdate', width:90},
   		{name:'name',index:'name', width:100},
   		{name:'amount',index:'amount', width:80, align:"right"},
   		{name:'tax',index:'tax', width:80, align:"right"},		
   		{name:'total',index:'total', width:80,align:"right"},		
   		{name:'note',index:'note', width:150, sortable:false}		
   	],
   	rowNum:10,
   	rowList:[10,20,30],
   	imgpath: gridimgpath,
   	pager: jQuery('#pager15'),
   	sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
	loadComplete: function(){
		var ret;
		alert("This function is executed immediately after\n data is loaded. We try to update data in row 13.");
		ret = jQuery("#list15").getRowData("13");
		if(ret.id == "13"){
			jQuery("#list15").setRowData(ret.id,{note:"<font color='red'>Row 13 is updated!</font>"})
		}
	}
});
jQuery("#sids").click( function() {
	alert("Id's of Grid: \n"+jQuery("#list15").getDataIDs());
});
</XMP>
<b>PHP with MySQL</b>
<XMP>
...
$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
if(!$sidx) $sidx =1;
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];

if( $count >0 ) {
	$total_pages = ceil($count/$limit);
} else {
	$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error());

$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $responce->rows[$i]['id']=$row[id];
    $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
    $i++;
}        
echo json_encode($responce);
...
</XMP>
</div>
//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer