我在mvc视图页面中有一个jqgrid,如下所示
$("#jqgrid").jqGrid({
url: "/Consultant/GetAll",
colNames: ['ConsultantId', 'Email', 'Status', 'Status'],
colModel: [
{ name: 'ConsultantId', index: 'ConsultantId', hidden: true },
{ name: 'ContactEmail', index: 'ContactEmail', sortable: true, search: true, autowidth: true, stringResult: true, shrinkToFit: true, searchoptions: { sopt: ['cn'] } },
{ name: 'Status', index: 'Status', hidden: true },
{
name: 'StatusChangeLink', sortable: true, autowidth: true, search: true, stype: "select",
searchoptions: {
value: "0:[All];1:Active;2:Inactive", sopt: ['eq'], defaultValue: 1,
}, align: 'center',
},
],
pager: '#pjqgrid',
datatype: "json",
rowNum: 10,
autowidth: true,
shrinkToFit: true,
height: 'auto',
forceFit: true,
rowList: [10, 20, 30],
sortname: 'ConsultantId',
sortorder: "desc",
loadonce: false,
viewrecords: true,
toolbarfilter: true,
gridview: true,
ignoreCase: true,
viewsortcols: [true, 'vertical', true],
ajaxGridOptions: { contentType: "application/json" },
jsonReader: {
root: 'Rows',
page: 'Page',
total: 'Total',
records: 'Records',
repeatitems: false
},
gridComplete: function () {
var ids = jQuery("#jqgrid").jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
var column = ids[i];
var row = $("#jqgrid").getRowData(column);
var statusChangeLink = '';
if (row['Status'] == 'true')
statusChangeLink = "<input type='checkbox' id='chk" + i + "' checked class='switch-input' onclick='ToggleIsActive(" + row['ConsultantId'] + ")'><label for='chk" + i + "' class='switch-label'></label>";
else if (row['Status'] == 'false')
statusChangeLink = "<input type='checkbox' id='chk" + i + "' class='switch-input' onclick='ToggleIsActive(" + row['ConsultantId'] + ")'><label for='chk" + i + "' class='switch-label'></label>";
$("#jqgrid").jqGrid('setRowData', column, { StatusChangeLink: statusChangeLink });
}
},
loadingText: 'Loading Consultants..',
noRecordText: 'No Records found',
});
$("#jqgrid").jqGrid('filterToolbar', { searchOnEnter: false, enableClear: false, defaultSearch: "cn", autosearch: true });
var grid = $("#jqgrid");
grid[0].triggerToolbar();
我正在从服务器端进行搜索,排序和分页,到目前为止工作正常。我目前的要求是,当我第一次显示网格时,我必须只显示网格中的活动(状态)顾问。如果用户需要查看非活动项目或所有项目,则可以更改下拉值。使用上面的代码将statuslink下拉列表设置为选中的值Active,但过滤器不会传递到服务器端(当我们检查服务器端的模型时,Status为0)。我应该怎么做才能让它发挥作用?
感谢任何帮助