2015-02-11 69 views
1

問題我試圖將其他值(作爲過濾器)傳遞給jquery bootgrid。在我的表單中,我有兩個日期範圍,每次更改日期時都需要刷新網格數據。jquery bootgrid requestHandler/post reload

處理器requestHandler和(過時)讓我傳遞給服務器的其他PARAMS尊重標準

但是,當我張貼了我的請求,我不能添加我的自定義參數。隨着螢火蟲我可以看到只有標準參數喜歡

current=1 
rowCount=10 
searchPhrase= 

請幫助我!

下面我完整的HTML代碼

<table id="grid-data" class="table table-condensed table-hover table-striped" data-toggle="bootgrid" data-ajax="true" data-url="HelpDesk/server.php"> 
        <thead> 
         <tr> 
         <th data-column-id="ticket_no" data-type="string" data-identifier="true">ticket_no</th> 
         <th data-column-id="title">title</th> 
               <th data-column-id="parent_id" data-type="string">parent_id</th> 
         <th data-column-id="contact_id" data-type="string">contact_id</th> 
         <th data-column-id="status">status</th> 
         <th data-column-id="priority" data-type="string">priority</th> 
               <th data-column-id="smownerid" data-type="string">smownerid</th> 
         </tr> 
        </thead> 

       </table> 

和我的js/jQuery代碼

<!-- now write the script specific for this grid --> 
<script language="javascript"> 
jQuery(document).ready(function() { 

    var grid = $("#grid-data").bootgrid({ 
     ajax: true, 
     url: "HelpDesk/server.php", 
     //requestHandler  
     //Transforms the JSON request object in what ever is needed on the server-side implementation. 
     // Default value is function (request) { return request; }. 
     requestHandler: function(request) 
     { 
      console.log("requestHandler - nevel called"); 
      console.log(request); 
      return request;  
     }/*, 
     post: function() 
     { 
      console.log("post - nevel called"); 
      return {datefrom:'aaaaaaaaa',dateto:'vvvvvvvvvv'}; 
     }*/ 
    }); 

    $('input[name="srch"]').click(function(){ 

     $("#grid-data").bootgrid("reload"); 
    }); 

}); 
</script> 

回答

2

要通過一些額外的信息到你的服務器,你只需要這些參數添加到request對象並返回它。例如:

requestHandler: function (request) { 
    request.myParam1 = "test"; 
    request.oneMoreMyParam = "test again"; 
    return request; 
} 

而在服務器端,您將收到這樣的事情:

current = 1, 
rowCount = 15, 
searchPhrase = "", 
myParam1 = "test", 
oneMoreMyParam = "test again" 

但是你寫的,你requestHandler從未被調用,對不對?它很奇怪。必須在"reload"事件中調用它。我也使用這個功能。此外,我不寫<table>的性能,如data-ajax="true" data-url="..."及用途:

<table id="grid-data" class="table table-condensed table-hover table-striped"> 
    <thead>...</thead> 
    <tbody>...</tbody> 
</table> 

<script type="text/javascript"> 
    $("#grid-data").bootgrid({ 
     ajax: true, 
     requestHandler: function (request) { 
      request.myParam= $("#some-input").val(); 
      return request; 
     }, 
     url: "..." 
    }); 

    $("#some-button").on("click", function() {   
     $("#grid-data").bootgrid("reload"); 
    }); 
</script> 

,一切運作良好。

0

對於任何來到這裏尋找答案的人。檢查您是否在表格元素上設置了data-toggle="bootgrid"。這似乎是重寫從js文件初始化手動bootgrid。刪除它爲我做了詭計。希望這可以幫助。