0
即時我陷入當我想創建子網格,總是顯示未捕獲的異常:jqGrid - 沒有這樣的方法:addSubGridCell我已經嘗試的示例,但即時通訊錯誤,,,這裏是JS即時通訊如此困惑我必須做的...subgrid jqgrid示例php mysql
$(document).ready(function(){
var grid = $("#list2");
grid.jqGrid({
url: 'json.php', //URL Tujuan Yg Mengenerate data Json nya
datatype: "json", //Datatype yg di gunakan
height: "auto", //Mengset Tinggi table jadi Auto menyesuaikan dengan isi table
mtype: "GET",
colNames: ['action','id','Agen','Suplier','Hotel','Check In', 'Check Out', 'ROOMs', 'Status', 'Group Hotel', 'Notes'],
colModel: [{name: 'myac', width:45, fixed:true, sortable:false, search:false, align:'center', resizable: false, resize:false, formatter:'actions',
formatoptions:{
keys:true,editbutton: true, delbutton: true, //Key True disini adalah untuk Shorcut Tombol Enter dan Esc, Enter untuk Save, dan Escape Untuk Batal, anda juga Membuatnya jadi False jika anda tidak ingin seperti itu
onSuccess:function(jqXHR) {
alert(jqXHR.responseText);
return true;
}
}
},
{name:'id', key:true, index:'id', hidden:true,editable:false,editrules:{required:true}},
{name:'agen',index:'agen',editable:true,editrules:{required:true}},
{name:'suplier',index:'suplier',editable:true,editrules:{required:true}},
{name:'hotel',index:'hotel',align:'center',editable:true,editrules:{required:true}},
{name:'checkin',index:'checkin',align:'center',editable:true,editrules:{required:true}},
{name:'checkout',index:'checkout',align:'center',editable:true,editrules:{required:true}},
{name:'rooms',index:'rooms',align:'center',editable:true,editrules:{required:true}},
{name:'status',index:'status',align:'center',editable:true,editrules:{required:true}},
{name:'groupHotel',index:'groupHotel',align:'center',editable:true,editrules:{required:true}},
{name:'notes',index:'notes',align:'center',editable:true,editrules:{required:true}}
],
rownumbers:true,
rowNum: 10,
rowList: [10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
editurl: "crud.php",
multiselect: false,
caption: "Record Test",
// subGrid: true,
// subGridUrl : "subrgrid1.php",
// subGridModel : [
// {
// name : ['ID', 'Id Reservation', 'Room Type', 'Total Room', ],
// width : [55, 200, 80, 80, 80],
// align : ['left','left','right','right','right'],
// params: ['rooms']
// }
// ]
});
grid.jqGrid('navGrid','#pager2',{view:true,edit:true,add:true,del:true});
});
讓我解釋一些,子網格的子網格的評論,沒有這個主網格是好的。
這裏是subgrid1.php
<?php
$db = mysql_connect("localhost","root","");
$con = mysql_select_db("ota",$db);
if(!$con){
echo "Something Problem";
}
$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
if(!$sidx) $sidx=1;
function ToSql ($field, $oper, $val) {
// we need here more advanced checking using the type of the field - i.e. integer, string, float
switch ($field) {
case 'nik':
//return intval($val);
//break;
case 'agen':
case 'suplier':
case 'hotel':
case 'checkin':
case 'checkout':
case 'checkin':
case 'rooms':
case 'status':
case 'groupHotel':
case 'notes':
//return floatval($val);
//break;
default :
//mysql_real_escape_string is better
if($oper=='bw' || $oper=='bn') return "'" . addslashes($val) . "%'";
else if ($oper=='ew' || $oper=='en') return "'%" . addcslashes($val) . "'";
else if ($oper=='cn' || $oper=='nc') return "'%" . addslashes($val) . "%'";
else return "'" . addslashes($val) . "'";
}
}
###For Single Searching###
//array to translate the search type
$ops = array(
'eq'=>'=', //equal
'ne'=>'<>',//not equal
'lt'=>'<', //less than
'le'=>'<=',//less than or equal
'gt'=>'>', //greater than
'ge'=>'>=',//greater than or equal
'bw'=>'LIKE', //begins with
'bn'=>'NOT LIKE', //doesn't begin with
'in'=>'LIKE', //is in
'ni'=>'NOT LIKE', //is not in
'ew'=>'LIKE', //ends with
'en'=>'NOT LIKE', //doesn't end with
'cn'=>'LIKE', // contains
'nc'=>'NOT LIKE' //doesn't contain
);
function getWhereClause($col, $oper, $val){
global $ops;
if($oper == 'bw' || $oper == 'bn') $val .= '%';
if($oper == 'ew' || $oper == 'en') $val = '%'.$val;
if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
return " WHERE $col {$ops[$oper]} '$val' ";
}
$where = ""; //if there is no search request sent by jqgrid, $where should be empty
$searchField = isset($_GET['searchField']) ? $_GET['searchField'] : false;
$searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: false;
$searchString = isset($_GET['searchString']) ? $_GET['searchString'] : false;
if ($_GET['_search'] == 'true') {
$where = getWhereClause($searchField,$searchOper,$searchString);
}
$data = mysql_query("SELECT COUNT(*) as count FROM reservation".$where);
$row = mysql_fetch_array($data);
$count = $row["count"];
//die($count);
$count > 0 ? $total_pages = ceil($count/$limit) :
$total_pages = 0;
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit;
if($start <0) $start = 0;
$data1 = mysql_query("SELECT * FROM reservation ".$where." ORDER BY $sidx $sord LIMIT $start, $limit");
$responce = new stdclass();
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($line = mysql_fetch_array($data1)){
$responce->rows[$i]['id'] = $line["id"];
$responce->rows[$i]['cell'] = array('',$line["id"],$line["agen"],$line["suplier"],$line["hotel"],$line["checkin"],$line["checkout"],$line["rooms"],$line["status"],$line["groupHotel"],$line["notes"]);
$i++;
}
echo json_encode($responce);
這裏是subgrid1.php
<?php
$examp = $_GET["q"];
$id = $_GET["idReservation"];
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die ("Connection ERROR : " .mysql_error());
mysql_select_db($database) or die ("Connection ERROR : " .mysql_error());
$sql = "SELECT id, idReservation, idRoomType, totalroom FROM roomtotal WHERE id=".$id" ORDER BY id";
$result = mysql_query($sql) or die (.mysql_error());
$i=0;
while ($row = mysql_fetch_array($result, mysql_assoc)) {
$responce->rows[$i]['$id']=$row["id"];
$responce->rows[$i]['cell']=array($row["id"], $row["idReservation"],$row["idRoomType"],$row["totalroom"]));
$i++;
}
echo $json->encode($responce);
我知道錯了SQL,但首先我想表明亞格:)之前 感謝