DIR : /home/kozerus/public_html/ko_center/js/jqgrid_demo35/rowedex1.html
/home/kozerus/public_html/ko_center/js/jqgrid_demo35
<div style="font-size:12px;">
This example shows the basic steps to make the grid editable. To do that we need 3 steps.<br>
1. Mark which column in the grid is editable. This is done with a new property "editable:true"<br>
By default all columns in the grid are not editable.<br>
2. Specify the url where the server accept the posted data. This is done with a option "editurl".<br>
3. Use the three new methods: editRow, saveRow, restoreRow.<br>
- <b>editRow(rowid, keys)</b> - accept two parametres:- rowid - the unique id of the row and keys - which <br>
when true - we can use Enter and Escape keys to save and cancel editing. <br>
- <b>saveRow( rowid, callback, url, extraparams)</b> <br>
rowid - unique id of the row, callback - custom function - when defined accept data returned from the server after posting, <br>
url - when specified - overwrite the editurl parameter, extraparams - additinal params that can be passed to the server.<br>
When data is posted the format is id=rowid&name=value..., where the name is the "name" from colModel.<br>
- <b>restoreRow( rowid)</b> - restores the data to original values before the editing of the row.<br>
<b>Note:</b> Due to security reasons data is not saved to this server.
</div>
<br />
<table id="rowed1" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="prowed1" class="scroll" style="text-align:center;"></div>
<br />
<input type="BUTTON" id="ed1" value="Edit row 13" />
<input type="BUTTON" id="sved1" disabled='true' value="Save row 13" />
<input type="BUTTON" id="cned1" disabled='true' value="Cancel Save" />
<script src="rowedex1.js" type="text/javascript"> </script>
<br />
<br />
<div style="font-size:12px;">
<b> HTML </b>
<XMP>
...
<table id="rowed1" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="prowed1" class="scroll" style="text-align:center;"></div>
<br />
<input type="BUTTON" id="ed1" value="Edit row 13" />
<input type="BUTTON" id="sved1" disabled='true' value="Save row 13" />
<input type="BUTTON" id="cned1" disabled='true' value="Cancel Save" />
<script src="rowedex1.js" type="text/javascript"> </script>
</XMP>
<b>Java Scrpt code</b>
<XMP>
...
jQuery("#rowed1").jqGrid({
url:'server.php?q=2',
datatype: "json",
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90, editable:true},
{name:'name',index:'name', width:100,editable:true},
{name:'amount',index:'amount', width:80, align:"right",editable:true},
{name:'tax',index:'tax', width:80, align:"right",editable:true},
{name:'total',index:'total', width:80,align:"right",editable:true},
{name:'note',index:'note', width:150, sortable:false,editable:true}
],
rowNum:10,
rowList:[10,20,30],
imgpath: gridimgpath,
pager: jQuery('#prowed1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
editurl: "server.php",
caption: "Basic Example"
}).navGrid("#prowed1",{edit:false,add:false,del:false});
jQuery("#ed1").click( function() {
jQuery("#rowed1").editRow("13");
this.disabled = 'true';
jQuery("#sved1,#cned1").attr("disabled",false);
});
jQuery("#sved1").click( function() {
jQuery("#rowed1").saveRow("13");
jQuery("#sved1,#cned1").attr("disabled",true);
jQuery("#ed1").attr("disabled",false);
});
jQuery("#cned1").click( function() {
jQuery("#rowed1").restoreRow("13");
jQuery("#sved1,#cned1").attr("disabled",true);
jQuery("#ed1").attr("disabled",false);
});
</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
Drag mouse to navigate.
Navigation
- Left/Right Mouse drag: Changes camera heading.
- Up/Sown Mouse drag: Changes camera pitch.
- Scroll wheel: Changes camera field of view.
- I-Key: Displays Info panel with canvas size, image size and FPS.
17.Aug.2010, Martin Wengenmayer