我已经使用Ajax调用填充了我的jqGrid。我在页面上有另一个下拉列表。现在我尝试根据在一列'FName'
的下拉列表中选择的值来过滤网格。但是网格没有被过滤掉。请参阅下面的代码并帮我修复它。
网格代码:
$("#jqGridAppointments").jqGrid({
url: "Default.aspx/GetData",
mtype: 'POST',
postData:
{
useMyFilter: "1",
},
datatype: "json",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
repeatitems: false,
root: function (obj) { return obj.d; }
},
colNames: ['Emp id', 'First Name', 'Last Name', 'Action'],
colModel: [
{ name: 'ID', dataField: 'ID', index: 'ID', key: true, hidden: true },
{ name: 'FName', dataField: 'FName', index: 'FName', width: 150 },
{ name: 'LName', dataField: 'LName', index: 'LName', width: 100 },
{
name: 'Edit', width: 50, edittype: 'select', formatter: 'showlink', formatoptions: {
baseLinkUrl: 'javascript:',
showAction: "ShowEditscreen('",
addParam: "');"
}
}
],
page: 1,
sortname: 'ID',
viewrecords: true,
sortorder: "asce",
caption: "Appointment Details",
gridview: true,
height: "auto",
loadonce: true,
search: true,
emptyrecords: "No records to view",
loadtext: "Loading...",
});
按钮的代码点击我试图过滤网格:
$("#btn").click(function () {
var filtertext = $("#ddlList").val();
var grid = $("jqGridAppointments");
var postdata = grid.jqGrid('getGridParam', 'postData');
$.extend(postdata, { filters: '', searchField: 'FName', searchOper: 'bw', searchString: filtertext });
grid.jqGrid('setGridParam', { search: true, postData: postdata });
grid.trigger("reloadGrid", [{ page: 1 }]);
});
需要注意的一点是,当我调试代码时,按钮单击行3中postdata
变量的值将变为undefined
。因为我是jqGrid
的新手,有人可以给我指点吗?
伙计们请帮助我,因为我无法继续前进。