2015-02-11 66 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。删除它为我做了诡计。希望这可以帮助。