单击列标题以升序显示 jqgrid
Posted
技术标签:
【中文标题】单击列标题以升序显示 jqgrid【英文标题】:Clicking a column header displays jqgrid in ascending order 【发布时间】:2013-01-21 10:52:39 【问题描述】:目前我在 java jqgrid 中工作排序。在此先感谢
代码:
jq(function()
var base = "<%=request.getContextPath()%>";
var records = -1;
jq("#grid").jqGrid(
url:base+'/admin/adminusermanagecrud.htm',
datatype: 'json',
mtype: 'GET',
colNames:['', 'Name','Employee ID','User Name','Mobile','City','State','Is Active','Created Date','Role','Bank Name'],
colModel:[
name:'id',index:'id', width:55,editable:false,hidden:true,
name:'adminName',index:'adminName', width:175,editable:true,sortable:true, editrules:edithidden:true,required:false, editoptions:size:25,readonly:false,disabled:false,search:false,
name:'adminEmployeeId',index:'adminEmployeeId', width:175,editable:true, editrules:edithidden:true,required:false, editoptions:size:25,readonly:true,disabled:false,search:true,
name:'adminuserName',index:'adminuserName', width:175,editable:true, editrules:edithidden:false,required:false, editoptions:size:25,readonly:false,disabled:false,search:true,
name:'mobile',index:'mobile', width:175,editable:true, editrules:edithidden:false,required:false, editoptions:size:25,disabled:false,search:true,
name:'city',index:'city', width:175,editable:true, editrules:edithidden:true,required:false, editoptions:size:25,disabled:true,search:true,
name:'state',index:'state', width:175,editable:true, editrules:edithidden:true,required:false, editoptions:size:25,disabled:true,search:true,
width:165,formatter:linkFormat,editable:true,edittype:'select',editrules:edithidden:true,required:false, editoptions:value:"0:Activate;1:De-Activate",size:25,disabled:false,multiple:false,search:false,
name:'createDate',index:'createDate',width:185,editable:true, editrules:edithidden:true,required:false, editoptions:size:25,disabled:true,search:false,
name:'role',index:'role',width:175,editable:true,editrules:edithidden:true,required:false,editoptions:size:25,disabled:true,search:false,
name:'bankName',index:'bankName',width:175,editable:true,editrules:edithidden:true,required:false,editoptions:size:25,disabled:true,search:false
],
postData:
,
loadError:function(xhr,status,error)
var base = "<%=request.getContextPath()%>";
alert(status);
if(xhr.status == '403' || xhr.status == '401' || status == 'parsererror')
window.location.href = base+"/login.htm";
,
rowNum:5,
//rowList:[5,10,15,20],
height: 150,
//width:750,
autowidth: true,
rownumbers: true,
pager: '#pager',
sortname: 'adminName',
scrollrows:true,
viewrecords: true,
sortorder: "asc",
caption:"Admin Users Summary",
onSortCol: function (index, columnIndex, sortOrder)
alert(index);
return 'stop';
,
cellEdit: false,
emptyrecords: "Search returned no results",
loadonce: false,
loadComplete: function()
,
jsonReader :
root: function(obj)
if(obj.status == false)
window.location.href = base+"/login.htm";
else
records = obj.records;
return obj.rows;
,
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
,
editurl:base+"/admin/edit.htm"
);
jq("#grid").navGrid('#pager',
edit:false,add:false,del:false,search:true,excel:true,
,
,
,
sopt:['eq','cn', 'bw', 'ew'],
closeOnEscape: true,
multipleSearch: false,
closeAfterSearch: true
);
jq("#btnFilter").click(function()
jq("#grid").jqGrid('searchGrid',
multipleSearch: false,
sopt:['eq']
);
);
);
【问题讨论】:
【参考方案1】:在您的控制器中,您需要处理排序。类似于
var pagedQuery = filteredQuery.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows);
您实际对数据集进行排序并将其返回给 jqGrid 的位置。
【讨论】:
以上是关于单击列标题以升序显示 jqgrid的主要内容,如果未能解决你的问题,请参考以下文章