我正在尝试将其他值(作为过滤器)传递给 jquery bootgrid。在我的表单中,我有两个日期范围,每次日期更改时我都需要刷新网格数据。
Handler requestHandler 和(已过时)post 允许我将其他参数传递给服务器,并遵守标准
但是当我发布请求时,我无法添加自定义参数。使用 Firebug,我只能看到标准参数,例如
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>
最佳答案
要将一些附加信息传递到您的服务器,您只需将这些参数添加到 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>
一切都很好。
关于jquery bootgrid 与 requestHandler/post 重新加载有关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28448087/