Question

I am trying to sort date in the dojo grid. But the sorting is not happening properly, it considers date as string and sorting doesn't work. Is there anyway that would help me?

My date format: EE MMM dd yyyy HH:mm:ss z

My code:

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();
});
Was it helpful?

Solution

As your date format is

EE MMM dd yyyy HH:mm:ss z

you might need to change your,

dojo.date.locale.parse(a,{datePattern:"dd/MM/yyyy hh:mm:ss",selector:"date"});

to have proper date format like below,

dojo.date.locale.parse(a,{datePattern:"EEE MMM dd yyyy HH:mm:ss Z",selector:"date"});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top