簡體   English   中英

搜索選項:jqGrid + PHP

[英]Search option: 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”列上的排序功能均無效。 我需要做什么?。 提前致謝。

我可以在您的服務器代碼中看到sidxsord參數的值上獨立使用的'order by id' (請參閱http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid作為正確示例服務器代碼)。

如果在jqGrid中使用datatype: 'json' ,則必須考慮的主要角色是sidxsord_search等其他參數將發送到服務器。 搜索選項(數據過濾)的功能相同,請參見http://www.trirand.com/jqgridwiki/doku.php?id=wiki:singe_searching了解更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM