【发布时间】:2011-11-14 08:09:16
【问题描述】:
我想加载一个默认排序的网格,它是字段之一。我通过将 sortname 和 sortorder 添加到我的网格来完成此操作,但是当加载网格时,排序符号会显示在该字段的标题上。但是当我单击分页下一个按钮而不是网格加载时,记录会被排序。
有谁知道为什么它不在网格负载上排序?
@更新: 嗨,kees,我使用我的数据类型作为 XML 和我的配置。如下:
jQuery("#userList").jqGrid({
url: '<%=request.getContextPath()%>/userJqGrid?q=1&action=fetchData&userCookie=<%= encodedCookie%>',
datatype: 'xml',
mtype: 'GET',
colNames:['<%= userProp.getProperty(userColNames[0])%>',
'<%= userProp.getProperty(userColNames[1])%>',
'<%= userProp.getProperty(userColNames[2])%>',
'<%= userProp.getProperty(userColNames[3])%>',
'<%= userProp.getProperty(userColNames[4])%>',
'<%= userProp.getProperty(userColNames[5])%>'
],
colModel:[
{name:'<%= userColNames[0]%>',index:'<%= userColNames[0]%>',
width:120,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:1, elmprefix:'*'}},
{name:'<%= userColNames[1]%>',index:'<%= userColNames[1]%>',
width:130,sortable:true,editable:true},
{name:'<%= userColNames[2]%>',index:'<%= userColNames[2]%>',
width:100,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:3, elmprefix:'*'}},
{name:'<%= userColNames[3]%>',index:'<%= userColNames[3]%>',
width:180,sortable:true,editable:true,editrules:{email:true,required:true},formoptions:{rowpos:4, elmprefix:'*'}},
{name:'<%= userColNames[4]%>',index:'<%= userColNames[4]%>',
width:100,sortable:true,editable:true},
{name:'<%= userColNames[5]%>',index:'<%= userColNames[5]%>',
width:100,sortable:true,editable:true},
],
pager:'#pager1',
rowNum:'<%=appProp.getProperty("per_page_records")%>',
height:'auto',
viewrecords:true,
loadonce:true,
sortable:true,
width:'100%',
gridview: true,
autowidth:true,
shrinkToFit:false,
ignoreCase:true,
editurl:'<%=request.getContextPath()%>/userJqGrid?q=1&action=addData&userCookie=<%=encodedCookie%>',
caption: 'User Records',
sortname:'<%=userColNames[14]%>',
sortorder:'asc',
onSelectRow: function (id){
checkAndSetCookie();
},
onSortCol : function(){
checkAndSetCookie();
},
onPaging : function(){
checkAndSetCookie();
},
onSearch : function(){
checkAndSetCookie();
},
loadComplete: function(){
checkAndSetCookie();
}
});
【问题讨论】:
-
您使用哪个数据后端?那么你的数据是如何加载的呢? JSON、本地数组等?您能否在此处发布您的 jqGrid 配置,以便我们为您提供帮助。
-
嗨,我已经添加并更新了我的配置。
-
如果您使用 FireBug(控制台)检查 URL 中是否有 sidx 和 sord 参数?
-
是的,网址中存在 idx=company_id&sord=asc,当我点击分页下一步按钮时,排序完成。
标签: jqgrid