0

当我想创建子网格时我卡住了,总是显示未捕获的异常:jqGrid - 没有这样的方法:addSubGridCell我已经尝试了示例,但是我遇到了错误,,,这是 JS 我很困惑我必须做什么......

$(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});               
        });

让我解释一下,子网格的子网格 URL 的评论,没有这个主网格是好的。

这是 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,但首先我想显示 subgrid :) 谢谢

4

1 回答 1

0

查看此文档: http ://www.trirand.net/documentation/php/index.htm (参见“jqSite php 文档/jqGrid PHP/Tutorials/Hierarchy/Subgrid 2 levels”,直接链接http://www.trirand。网络/文档/php/_2v90kv1k9.htm)。当grid和subgrid都在php文件中时有写,但我想你会弄清楚如何用js编写一个grid,用php编写subgrid。

于 2012-11-04T16:47:45.467 回答