Frage

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();
});
War es hilfreich?

Lösung

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"});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top