3
我認爲,jqgrid作爲變量發送時,你編輯一個行,列名稱,但在我創建這個網格似乎不工作,除非我在php中犯了一個錯誤的地方。 jqgrid將哪些方法發送到服務器?jqgrid編輯操作如何向服務器發送變量?
這是我的代碼。
的Index.html
<script type="text/javascript">
$(function(){
var mygrid = $("#list");
mygrid.jqGrid({
url:'example1.php',
editurl: 'edit.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
colModel :[
{name:'invid',
index:'invid',
width:55
},
{name:'invdate',
index:'invdate',
width:90,
editable:true
},
{name:'amount',
index:'amount',
width:80,
align:'right',
search:true ,
stype:'select',
searchoptions:{value:':All;8:8.00;6:6.00'},
editable:true
},
{name:'tax',
index:'tax',
width:80,
align:'right',
editable:true
},
{name:'total',
index:'total',
//width:80,
align:'right',
sortable:true,
editable:true,
editrules:{required:true},
edittype:'select',
editoptions:{value:"5:55.00;2:25.00"}
},
{name:'note',
index:'note',
width:150,
search:true ,
align:'center',
editable:true,
editrules:{required:true, edithidden:true},
hidden:true,
edittype:'textarea',
editoptions: {rows:"12",cols:"10"}
}
],
pager: '#pager',
emptyrecords: "Nothing to display",
recordtext: '{0} - {1} of {2}',
rowNum:9,
rowList:[7,9,11],
viewrecords: true,
caption: 'My first grid',
sortname: 'invid',
sortorder: 'desc',
loadonce : true
});
//Search button
$("#bsdata").click(function(){ mygrid.jqGrid('searchGrid', {sopt:['eq'],top:300,caption:"test searching"}); });
// Search toolbar.
mygrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "eq"});
//NavBar
mygrid.jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:true});
// Edit Row
$("#bedata").click(function(){
var gr = mygrid.jqGrid('getGridParam','selrow');
if(gr != null)
mygrid.jqGrid('editGridRow',gr,{height:480,reloadAfterSubmit:false});
else alert("Please Select Row");
});
// Add row
$("#badata").click(function(){
mygrid.jqGrid('editGridRow',"new",{height:480,reloadAfterSubmit:false});
});
// Delete row
$("#bddata").click(function(){
var gr = mygrid.jqGrid('getGridParam','selrow');
if(gr != null)
mygrid.jqGrid('delGridRow',gr,{reloadAfterSubmit:false});
else
alert("Please Select Row to delete!");
});
});
</script>
和edit.php
<?php
// connect to the database
$dbhost = "localhost";
$dbuser = "user";
$dbpassword = "user123";
$database = "test";
$tablename = "invheader";
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error conecting to db.");
//mysql_set_charset('utf8',$database);
mysql_query("SET NAMES 'utf8'");
if($_GET['oper']=='add')
{
}
if($_GET['oper']=='edit')
{
$id = mysql_real_escape_string($_GET['id']);
$date = mysql_real_escape_string($_GET['invdate']);
$amount = mysql_real_escape_string($_GET['amount']);
$tax = mysql_real_escape_string($_GET['tax']);
$total = mysql_real_escape_string($_GET['total']);
$note = mysql_real_escape_string($_GET['note']);
$sql = "UPDATE ".$tablename." SET invdate = '".$date."', client_id = '5' , amount = '".$amount."', tax = '".$tax."', total = '".$total."' , ";
$sql.= "note = '".$note."'";
$sql.= " WHERE invid = ".$id;
echo $sql;
$result=mysql_query($sql) or die(mysql_error());
mysql_close($db);
}
if($_GET['oper']=='del')
{
}
?>
感謝您的時間。
謝謝,我正在尋找相同的 – Pradeep
@FN,這個問題和你的答案幫助我終於理解了如何通過jqgrid編輯POST到php。那謝謝啦。 – user
謝謝,這對我有很大的幫助。 – JuanFernandoz