问题描述
我想通过JavaScript将搜索手动应用于我的jqGrid.我已经在此处尝试过指南,但是可以似乎无法使其完全正常工作.在网格设置中,我有一列名为"error_column"的列,我希望在查找字符串"Test"时执行搜索.
I would like to manually apply searching to my jqGrid via JavaScript. I have tried a guide here, but can't seem to get it completely working.In the grid setup I have a column with name 'error_column' that I would like to perform a search on looking for the string 'Test'.
这是我到目前为止所拥有的:
Here is what I have so far:
var filter = { "field": "error_column", 'oper': 'eq', "data": 'Test' };
$("Grid2").jqGrid('setGridParam', { search: true, postData: { filters: filter} })
$("Grid2").trigger('reloadGrid');
当我单击绑定到的按钮时,什么也没有发生,也没有导致错误.
When I click the button that this is bound to, nothing happens and it causes no errors.
编辑这是初始化网格的代码:
EDITHere is the code for initializing the grid:
jQuery("#Grid2").jqGrid({
datatype: "local",
height: 250,
colNames: ['NewSubscriberID', 'Conflicting Subscriber ID', 'Error Field', 'Error Message'],
colModel: [
{ name: 'new_subscriber_id', index: 'new_subscriber_id', width: 120},
{ name: 'conflicting_subscriber_id', index: 'conflicting_subscriber_id', width: 170},
{ name: 'error_column', index: 'error_column', width: 90, sorttype: "text", search: true},
{ name: 'error_type', index: 'error_type', width: 145}
],
loadonce: true
});
我使用本地数组将数据绑定到网格.
I bind the data to the grid using a local array.
推荐答案
您应该以另一种方式实现对单个字段的搜索:
You should implement search for single field in a little another way:
var grid = jQuery("#Grid2");
var postdata = grid.jqGrid('getGridParam','postData');
jQuery.extend (postdata,
{filters:'',
searchField: 'error_column',
searchOper: 'eq',
searchString: 'Test'});
grid.jqGrid('setGridParam', { search: true, postData: postdata });
grid.trigger("reloadGrid",[{page:1}]);
您可以在此处看到实时示例.
You can see live example here.
已更新:您同时使用loadonce: true
和datatype: "local"
.在datatype: "local"
的情况下,值loadonce: true
将被忽略.如果确实从服务器获取数据并使用datatype: "json"
或datatype: "xml"
,则loadonce: true
将起作用.如果希望搜索(过滤)不是在本地进行,而是在服务器上进行,则应将datatype
重置为'json'
或'xml'
作为'setGridParam'
的附加选项.
UPDATED: You use loadonce: true
and datatype: "local"
together. The value loadonce: true
will be ignored in case of datatype: "local"
. If you do get the data from the server and use datatype: "json"
or datatype: "xml"
, then loadonce: true
will work. If you want that the searching (filtering) will be done not locally but on the server instead you should reset datatype
to 'json'
or 'xml'
as additional option of 'setGridParam'
.
这篇关于jqGrid客户端搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!