搜索选项:jqGrid + PHP

时间:2010-06-09 05:00:06

标签: php jquery jqgrid jqgrid-php

我正在尝试使用此代码:

$("#list").jqGrid({
                    url: 'employers.php',
                    datatype: 'json',
                    mtype: 'POST',
                    postData: {c : "", n: "", a: "", d: "", t: "", e: "", f: "", g: $('#selectSalary').value(), p: "", call: "report"},
                    colNames: ['ID','Name', 'Surname', 'Department', 'E-mail','Phone', 'Title in'],
                    colModel: [
                      { name:'rows.id',                index: 'id',   search:true, jsonmap: 'id', width: 50, align: 'left', sortable:true},
                      { name:'rows.name',                index: 'name',    jsonmap: 'name', width: 150, align: 'left'},
                      { name:'rows.surname',              index: 'surname',  jsonmap: 'surname', width: 240, align: 'left'},
                      { name:'rows.department',             index: 'department', jsonmap: 'department',  width: 330, align: 'left'},
                      { name:'rows.email',                 index: 'email',     jsonmap: 'email',width: 200, align: 'left'},
                      { name:'rows.phone',              index: 'phone',  jsonmap: 'phone', width: 170, align: 'left'},
                      { name:'rows.title', index: 'title', jsonmap: 'title',width: 120, align: 'left'}],

                    pager: '#pager',
                    rowNum: 8,
                    autowidth: true,
                    rowList: [10, 20],
                    sortname: 'id',
                    sortorder: 'asc',
                    viewrecords: true,
                    caption: "Employer's Salary",
                    jsonReader : {
                                    root: "rows",
                                    repeatitems: false
                                  },
                    height: 350,
                    width: 900
            });


$("#list").jqGrid('navGrid','#pager',{search:true, searchtext: "search",edit:false,add:false,del:false});

我正在使用的HMTL:

<div id="report">
        <table id="list"></table>
        <div id="pager">
        </div>
<div>

PHP代码:

$total_pages = 0;
$limit=10;
//Using QCubed, a PHP Framework and PDO
$count = Employers::CountAll();
if($count> 0)
$total_pages= ceil($count/$limit);
else
$total_pages=0;
$cnx = new PDO("mysql:host=localhost;dbname=appsms","root","");
$rows = array();
$strQuery="select id, name, surname, department, phone, email, title from Employer join Titles on " .
                           " (employers.title = Titles.id) and (employers.g = '"  .$this->g .
                           "') order by id;";

$stmt = $cnx->prepare($strQuery);
$stmt->execute(array("report"));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$response->page = 1;
$response->total=  $total_pages;
$response->records = sizeof($rows);

$i=0;
foreach($rows as $result){
$response->rows[$i] = $result;
$i++;
}


echo json_encode($response);

它从PHP加载查询,但搜索选项既不适用于“cedula”列上的排序功能。我需要做什么?。提前致谢。

1 个答案:

答案 0 :(得分:1)

我可以在您的服务器代码'order by id'中看到对sidxsord参数的值使用了indepand(请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid作为正确服务器代码的示例)。< / p>

如果您在jqGrid其他参数datatype: 'json'sidxsord中使用_search,则必须采取的主要角色将被发送至服务器。这与搜索选项(数据过滤)相同,请参阅http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching以获取更多信息。