jqgrid搜索/过滤
jqgrid search/filter
这与我在这个链接中最近的问题有关。我已经弄清楚了错误是什么,为什么它显示"服务器错误:参数'dataType'未指定"。是filter="[{'name':'main_account_group_code','comparison':'starts_with','value':$('#searchCode').val()}]";
filter=[{'name':'main_account_group_code','comparison':'starts_with','value':$('#searchCode').val()}];
现在,我的网格成功地显示了搜索中的数据。我的问题是,有没有另一种方法来做到这一点,而不使用全局变量?我的前辈告诉我,这是一个不好的做法,并尝试其他的东西。我也有这种感觉,仍然有一个最好的方式来显示我的搜索数据在jqgrid(而不是使用全局),但我只是不知道如何做到这一点。
我已经自己解决这个问题好几天了,但是我仍然没有最好的方法来做这个(仍然卡住)。有人帮助. .
编辑:这是我的jqgrid代码。
$("#list1").jqGrid({
url: '',
datatype: 'local',
jsonReader : {
root: function(obj) {
var root = [];
if ('error' in obj)
{
showMessage(obj.error['class'] + ' error: ' + obj['error']['msg']);
}
else
{
$.each(obj['result']['main']['rowdata'], function(rowIndex, rowDataValue) {
var row = {};
$.each(rowDataValue, function(columnIndex, rowArrayValue) {
var fldName = obj['result']['main']['metadata']['fields'][columnIndex].name;
row[fldName] = rowArrayValue;
});
root[rowIndex] = row;
});
};
return root;
},
page: "result.main.page",
total: "result.main.pageCount",
records: "result.main.rows",
repeatitems: false,
id: "0"
},
colNames:['Code', 'Description','Type'],
colModel:[
{name:'code'},
{name:'desc'},
{name:'type'}
],
postData: {
filters:[{"name":"main_account_group_code", "comparison":"starts_with", "value":$('#searchCode').val()}]
},
rowNum:10,
viewrecords: true,
rowList:[10,50,100],
pager: '#tblDataPager1',
sortname: 'desc',
sortorder: 'desc',
loadonce:false,
height: 250,
caption: "Main Account"
});
你在上一个问题中使用的方式我不喜欢,不是因为使用"全局"变量filter
,而是因为复杂的逻辑。特别奇怪的是,我发现你在serializeGridData
事件句柄的实现中丢弃了jqGrid的许多参数。我相信,代码可以大大简化,但你没有张贴更完整的JavaScript代码,你使用。甚至您使用哪种HTTP方法与服务器通信(是否使用mtype:"POST"
参数)。
现在谈谈你的主要问题。变量filter
应该而不是是全局的。它应该是可见的。例如:
$(document).ready(function () {
var filter = ''; //this is NOT global variable
$('#btnsearchCode').click(function(){
filter="...any value..."; // you can change the value of filter here
//...
$('#list1').trigger('reloadGrid');
});
$('#list1').jqGrid({
// define jqGrid where you can use filter if needed
// either directly of inside of body of any function
});
});
相关文章:
- 停止 jQuery 自动完成以过滤/搜索结果并填充整个源数组数据
- 使用jquery从json过滤搜索
- 如何在制作角度为2的搜索管道时过滤javascript对象
- backbone.js搜索过滤系统[Structure]
- 在可过滤的剑道移动搜索框中键入时执行功能
- 构建可搜索/过滤数据库
- 使用复选框 php 过滤搜索
- 无法使用角度智能表进行排序/过滤/搜索
- 基于NodeJS中的其他数组过滤/搜索对象的JavaScript数组
- AngularJS:根据格式化日期进行过滤/搜索
- AngularJS正在过滤搜索结果:Error: [ng:areq]
- 如何过滤/搜索多维数组的对象
- 仅对PNG图像过滤搜索结果
- 如何使用php从mysql数据库中提炼/过滤搜索结果
- 如何刷新过滤搜索时的“清除”按钮;在文本的边缘点击
- 如何使用javascript过滤搜索结果
- 在html表中动态过滤搜索结果
- 如何进一步过滤搜索步骤中的结果
- 根据前一个下拉选项更改下拉选项(过滤搜索)
- 过滤搜索结果typeahead.js