我有一个名为“Day”的专栏,在我的jqgrid中有一天的名字。我无法弄清楚如何按星期顺序排序,而不是按字母顺序排序。
有什么想法吗?有没有办法覆盖默认的排序行为?
谢谢!
答案 0 :(得分:0)
首先,您需要在数据源中包含一个计算字段,该字段表示星期几作为数字。然后,更新您的colModel,以便您当前的“Day”字段使用该计算的数字,方法是设置该列的“index”值:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options
参见“index”选项
...
{name:'DAY', label:'Day', index: 'DayAsNumber',} },
...
答案 1 :(得分:0)
我正在使用数据类型作为JSON。您可以在我的代码中看到“dayOfWeek”列。 我想我必须在我的select editoption中使用一个数字作为editoptions:{value:“1:Monday; 2:Tuesday ...},然后按索引排序?
jq(function() {
jQuery("#grid").jqGrid({
url:'/ocr/webadmin/crudslsrouting?region='+document.getElementById("selectregion").value,
datatype: 'json',
mtype: 'GET',
colNames:['id', 'weekAndGap', '<fmt:message key="slsrouting.year"/>', '<fmt:message key="slsrouting.week"/>', '<fmt:message key="slsrouting.region"/>', '<fmt:message key="slsrouting.dayOfWeek"/>', '<fmt:message key="slsrouting.timeFrom"/>', '<fmt:message key="slsrouting.timeto"/>', '<fmt:message key="slsrouting.1stTechnician"/>', '<fmt:message key="slsrouting.1stTechnicianNumber1"/>', '<fmt:message key="slsrouting.1stTechnicianNumber2"/>', '<fmt:message key="slsrouting.2ndTechnician"/>', '<fmt:message key="slsrouting.2ndTechnicianNumber1"/>', '<fmt:message key="slsrouting.2ndTechnicianNumber2"/>', '<fmt:message key="slsrouting.3rdTechnician"/>', '<fmt:message key="slsrouting.3rdTechnicianNumber1"/>', '<fmt:message key="slsrouting.3rdTechnicianNumber2"/>', '<fmt:message key="slsrouting.smsGroup"/>'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true},hidden:true},
{name:'weekAndGap',index:'weekAndGap', width:55,editable:false,editoptions:{readonly:true},hidden:true},
{name:'year',index:'year', width:25,editable:false,editoptions:{readonly:true},hidden:true},
{name:'week',index:'week', width:25,sorttype: 'integer',editable:true, editrules:{required:true}},
{name:'region',index:'region', width:55,editable:true,editoptions:{required:true}},
{name:'dayOfWeek',index:'dayOfWeek', width:50,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"Monday:Monday;Tuesday:Tuesday;Wednesday:Wednesday;Thursday:Thursday;Friday:Friday;Saturday:Saturday;Sunday:Sunday"}},
{name:'timeFrom',index:'timeFrom', width:40,editable:true, editrules:{required:true}, editoptions:{dataInit: function (el) {jq(el).timepicker({});}}},
{name:'timeTo',index:'timeTo', width:40,editable:true, editrules:{required:true}, editoptions:{dataInit: function (el) {jq(el).timepicker({});}}},
{name:'technicianId1',index:'technicianId1', width:70,editable:true, editrules:{required:true}, edittype:"select"},
{name:'technician1PhoneNumber1',index:'technician1PhoneNumber1', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'technician1PhoneNumber2',index:'technician1PhoneNumber2', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'technicianId2',index:'technicianId2', width:70,editable:true, editrules:{required:true}, edittype:"select"},
{name:'technician2PhoneNumber1',index:'technician2PhoneNumber1', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'technician2PhoneNumber2',index:'technician2PhoneNumber2', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'technicianId3',index:'technicianId3', width:70,editable:true, editrules:{required:true}, edittype:"select"},
{name:'technician3PhoneNumber1',index:'technician3PhoneNumber1', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'technician3PhoneNumber2',index:'technician3PhoneNumber2', width:70,editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"-:-;Office Phone:Office Phone;Mobile Phone:Mobile Phone;Other Phone:Other Phone"}},
{name:'smsGroupId',index:'smsGroupId', width:70,editable:true, editrules:{required:true}, edittype:"select"}
],
editurl: "/ocr/webadmin/crudslsrouting/edit",
rowNum:300,
rowList:[300,600,900,1200],
height: 400,
autowidth: true,
rownumbers: true,
pager: '#pager',
viewrecords: true,
caption:"SL Routing",
emptyrecords: '<fmt:message key="common.emptyRecords"/>',
async: false,
loadonce: true,
loadComplete: function() {
if(document.getElementById("defaultRegion").value!='ALL' ||
(document.getElementById("selectregion").value!="" && document.getElementById("selectregion").value!="ALL")){
var regionValue=document.getElementById("selectregion").value;
getNicknameList(regionValue);
getSmsgroupList(regionValue);
//testIfNoWeek0ForSLAndRegion(regionValue);
}
//testIfWeek0TotallyCovered();
},
loadError : function(xhr,st,err) {
jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
grouping:true,
groupingView : { groupField : ['weekAndGap'],
groupDataSorted : true,
groupColumnShow : [false],
groupCollapse : true,
groupText : ['<fmt:message key="slsrouting.week"/> {0} <fmt:message key="slsrouting.covered"/> - {1} Item(s) <a class="ui-group-div ui-corner-all" href="Javascript:DuplicateAllTheWeek(\'{0}\');"><span class="ui-duplicate-image-link"></span> <fmt:message key="slsrouting.duplicate"/></a> <a class="ui-group-div ui-corner-all" href="Javascript:DeleteWeek(\'{0}\');"><span class="ui-delete-button-link"></span> <fmt:message key="common.delete"/></a> ']
},
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
}
});
jq("#grid").jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:false});
jq("#grid").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false,
afterSearch : function(){
if(jq("#gs_StateFull").val() == "") {
jq("#grid").jqGrid('setGridParam',{groupingView: { groupCollapse : true} }).trigger('reloadGrid');
} else {
jq("#grid").jqGrid('setGridParam',{groupingView: { groupCollapse : false} }).trigger('reloadGrid');
}
}
});
jq("#grid").navButtonAdd('#pager',
{ caption:'<fmt:message key="common.add"/>',
buttonicon:"ui-icon-plus",
onClickButton: addRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#grid").navButtonAdd('#pager',
{ caption:'<fmt:message key="common.edit"/>',
buttonicon:"ui-icon-pencil",
onClickButton: editRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#grid").navButtonAdd('#pager',
{ caption:'<fmt:message key="common.delete"/>',
buttonicon:"ui-icon-trash",
onClickButton: deleteRow,
position: "last",
title:"",
cursor: "pointer"
}
);
});