2013-05-01 123 views
1

我有一個jqGrid不使用loadonce:true選項。服務器在發送每個查詢時動態地處理排序。唯一的事情是每個頁面顯示相同的數據。當我點擊列標題時,數據會被正確排序,但我無法獲取不同的頁面顯示。jqgrid尋呼機不顯示數據

這是處理排序的函數。這是基本相同http://www.trirand.com/jqgridwiki/doku.php?id=wiki:first_grid & S []除在Postgres,而不是MySQL的

function popGrid($conn){ 
    $page = $_POST['page']; 
    $limit = $_POST['rows']; 
    $sidx = $_POST['sidx']; 
    $sord = $_POST['sord']; 
    $sqlCount = $_POST['sqlCount']; 
    $sqlSelect = $_POST['sqlSelect']; 
    $sqlSelect2 = $_POST['sqlSelect2']; 
    $sqlSelect3 = $_POST['sqlSelect3']; 
    $label1 = $_POST['label1']; 
    $label2 = $_POST['label2']; 
    $lbl1 = $_POST['lbl1']; 
    $lbl2 = $_POST['lbl2']; 
    $lbl3 = $_POST['lbl3']; 

    if(!$sidx){ $sidx = 1; } 

    $query = pg_query($conn,$sqlCount); 
    $row = pg_fetch_row($query); 
    $count = $row[0]; 

    if($count > 0 && $limit > 0){ $total_pages = ceil($count/$limit); } 
    else{ $total_pages = 0; } 

    if($page > $total_pages){ $pages = $total_pages; } 

    $start = $limit*page - $limit; 

    if($start < 0){ $start = 0; } 

    header("Content-type: text/xml;charset=utf-8"); 

    $s = "<?xml version='1.0' encoding='utf-8'?> 
     <rows> 
     <page>".$page."</page> 
     <total>".$total_pages."</total> 
     <records>".$count."</records>"; 

    $sqlSelect .= " ORDER BY $sidx $sord LIMIT $limit OFFSET $start "; 
    $query = pg_query($conn,$sqlSelect); 
    while($row = pg_fetch_row($query)){ 
     $s .= "<row id='".$row[0]."'>"; 
     if($lbl1){ $s .= "<cell>$lbl1</cell>"; } 
     $s .= "<cell>".$row[0]."</cell> 
       <cell>".$row[1]."</cell>"; 
     if($label1){ $s.= "<cell>$label1</cell>"; } 
     $s .= "<cell>".$row[2]."</cell> 
       <cell>".$row[3]."</cell> 
       <cell>".$row[4]."</cell> 
       <cell>".$row[5]."</cell> 
       <cell>".$row[6]."</cell> 
       <cell>".$row[7]."</cell> 
       <cell>".$row[8]."</cell> 
       <cell>".$row[9]."</cell> 
       <cell>".$row[10]."</cell> 
       <cell>".$row[11]."</cell> 
       <cell>".$row[12]."</cell> 
       <cell>".$row[13]."</cell> 
       <cell>".$row[14]."</cell> 
       <cell>".$row[15]."</cell> 
       </row>"; 
    } 
    if($sqlSelect2){ 
     $sqlSelect2 .= " ORDER BY $sidx $sord LIMIT $limit OFFSET $start "; 
     $query = pg_query($conn,$sqlSelect2); 
     while($row = pg_fetch_row($query)){ 
      $s .= "<row id='".$row[0]."'>"; 
      if($lbl2){ $s .= "<cell>$lbl2</cell>"; } 
      $s .= " <cell>".$row[0]."</cell> 
        <cell>".$row[1]."</cell>"; 
      if($label2){ $s .= "<cell>$label2</cell>"; } 
      $s .= "<cell>".$row[2]."</cell> 
        <cell>".$row[3]."</cell> 
        <cell>".$row[4]."</cell> 
        <cell>".$row[5]."</cell> 
        <cell>".$row[6]."</cell> 
        <cell>".$row[7]."</cell> 
        <cell>".$row[8]."</cell> 
        <cell>".$row[9]."</cell> 
        </row>"; 
     } 
    } 
    if($sqlSelect3){ 
     $sqlSelect3 .= " ORDER BY $sidx $sord LIMIT $limit OFFSET $start "; 
     $query = pg_query($conn,$sqlSelect3); 
     while($row = pg_fetch_row($query)){ 
      $s .= "<row id='".$row[0]."'>"; 
      if($lbl3){ $s .= "<cell>$lbl3</cell>"; } 
      $s .= " <cell>".$row[0]."</cell> 
        <cell>".$row[1]."</cell>"; 
      if($label2){ $s .= "<cell>$label2</cell>"; } 
      $s .= "<cell>".$row[2]."</cell> 
        <cell>".$row[3]."</cell> 
        <cell>".$row[4]."</cell> 
        <cell>".$row[5]."</cell> 
        <cell>".$row[6]."</cell> 
        <cell>".$row[7]."</cell> 
        </row>";    
     } 
    } 
    $s .= "</rows>"; 
    echo $s; 

} 

這裏= SIDX的網格,如果是這樣的問題:

$('#lst_users').jqGrid({ 
    url: 'hours_func.php', 
    dataType: 'xml', 
    mtype: 'POST', 
    postData: { 
     action: 'popGrid', 
     sqlCount: sqlCount, 
     sqlSelect: sqlSelect 
    }, 
    colNames:['ID','LOGIN ID','PASSWORD','FIRST NAME','LAST NAME','EMAIL','ADMIN'], 
    colModel:[ 
     { name: 'id', 
      required: false, 
      editable: false, 
     }, 
     { name: 'login_id', 
      editoptions: { 
       maxlength: 4 
      } 
     }, 
     { name: 'password', 
      editoptions: { 
       maxlength: 30 
      } 
     }, 
     { name: 'fname', 
      editoptions: { 
       maxlength: 20 
      } 
     }, 
     { name: 'lname', 
      editoptions: { 
       maxlength: 30 
      } 
     }, 
     { name: 'email', 
      required: false, 
      editoptions:{ 
       maxlength: 30 
      } 
     }, 
     { name: 'admin', 
      editoptions: { 
       dataInit: function(elem){ 
        $(elem).mask("~"); 
       } 
      } 
     },  
    ], 
    cmTemplate:{ 
     align: 'center', 
     colwidth: 80, 
     editable: true, 
     required: true, 
    }, 
    caption: 'Users', 
    pager:'#pgr_users', 
    editurl: 'hours_func.php', 
    loadonce: false, 
}).navGrid('#pgr_users', 
    //include all buttons 
    { search: false, 
    }, 
    //edit options 
    { bSubmit: "Edit", 
     width: 350, 
     recreateForm: true, 
     recreateFilter: true, 
     closeOnEscape: true, 
     editData: { 
      action: 'grdUsers', 
      id: function(){ 
       var id = $('#lst_users').jqGrid('getGridParam','selrow'); 
       var val = $('#lst_users').jqGrid('getCell',id,'id'); 
       return val; 
      } 
     }, 
    }, 
    //add options 
    { bSubmit: "Add", 
     width: 350, 
     recreateForm: true, 
     recreateFilter: false, 
     closeOnEscape: true, 
     editData: { action: 'grdUsers' } 
    }, 
    //delete options 
    { recreateForm: false, 
     recreateFilter: false, 
     closeOnEscape: true, 
     delData: { 
      action: 'grdUsers', 
      id: function() { 
       var sel_id = $('#lst_users').jqGrid('getGridParam','selrow'); 
       var value = $('#lst_users').jqGrid('getCell', sel_id, 'id'); 
       return value; 
      } 
     } 
    }, 
    //search options 
    {}, 
    //view options 
    {} 
); 

回答

2

您設置分頁的方式將在服務器端處理。如果您使用Firebug或類似的東西,您可以看到jqGrid會將信息發送到您的控制器,以便您可以過濾到正確的頁面。您的控制器已經處理數據的排序,所以現在您只需要利用尋呼信息來獲取正確的數據頁面。

下面的代碼是C#,但它會作爲一個例子:

控制器將收到的頁面請求,從jqGrid的職位的以下信息

GetGridData(string sidx, string sord, int page, int rows, bool _search, string filters) 
{ 
.... 

然後可以使用這個信息來過濾jqGrid請求的數據頁面,就像我在這個例子中做的那樣。

... 
var pagedQuery = DataSet.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows).ToList(); 
... 
+0

我覺得這樣的菜鳥。我正在處理排序很好,但我沒有把我的一個php變量($ page變量)放在$ :(謝謝你試圖提供幫助)。從技術上講,你的建議對於我認爲的問題是合理的。在這種情況下,接受協議是什麼?我只是不想誤導任何人在未來訪問此頁面。 – user 2013-05-01 20:37:38

+1

@MWall嗯,我回答了你提出的問題,並將其標記爲正確,以便將來可以找到它如果有人遇到上述問題。 – Mark 2013-05-02 11:49:48