我正在尝试在dojo网格中对日期进行排序。但排序没有正确发生,它将日期视为字符串,排序不起作用。反正有什么可以帮到我吗?
我的日期格式:EE MMM dd yyyy HH:mm:ss z
我的代码:
myStore = new ItemFileWriteStore({
data:storeData
});
myStore.comparatorMap = {};
myStore.comparatorMap["scan_date"] = function(a,b){
var af = dojo.date.locale.parse(a,{datePattern:"dd/MM/yyyy hh:mm:ss",selector:"date"});
var bf = dojo.date.locale.parse(b,{datePattern:"dd/MM/yyyy hh:mm:ss",selector:"date"});
var c = dojo.date.compare(af, bf);
return c;
}
// myStore.comparatorMap = {};
// myStore = new ObjectStore({ objectStore:new Memory({ data: data }) });
grid = new DataGrid({
store: myStore,
query: { id: "*" },
queryOptions: {},
structure: [
{ type: "dojox.grid._RadioSelector" },
[
// {name:'S.No.', field: 'Id', width: '47px'},
{name:"Client Name",field:"client_name",width: "auto"},
{name:"Contractor Name",field:"contractor_name",width: "auto"},
{name:"Barcode Number",field:"barcode_number",width: "auto"},
{name:"Replacement Seal Number",field:"container_number",width: "auto"},
{name:"Container Number",field:"container_no",width: "auto"},
{name:"Address",field:"address",width: "auto"},
{name:"Scan Date & Time",field:"scan_date",datatype:"date",width: "auto",formatter:formatDate},
{name:"Contractor Remarks",field:"contractor_remarks",width: "auto"}
]
]
}, "grid");
grid.startup();
});
答案 0 :(得分:2)
由于您的日期格式为
EE MMM dd yyyy HH:mm:ss z
你可能需要改变你的,
dojo.date.locale.parse(a,{datePattern:"dd/MM/yyyy hh:mm:ss",selector:"date"});
具有如下所示的正确日期格式
dojo.date.locale.parse(a,{datePattern:"EEE MMM dd yyyy HH:mm:ss Z",selector:"date"});