Topic: table sorting not working for date column
modadvisor asked 3 years ago
date column sorting not working.
my date format is MM/DD/YYYY when i click on header it sorts with month only not considered day and years. please let me know how can i do it ?
{
label: "From",
field: "eff_date",
datepicker: true,
sorting : true
}
please guide me the modification required. Thanks
frankvdsm pro premium priority answered 3 years ago
First of all: make sure taht the date in your datasource table is in the format YYY-MM-DD.
Don't apply the format to your datatable but create a function like this:
public showTimestamp(n: string) {
let y = n.substr(0,4);
let m = n.substr(5,2);
let d = n.substr(8, 2);
return d + "/" + m + "/" + y; }
in your HTML us this function like this:
{{ showTimestamp(v.datum) }}
Your data is always shown in the right format and is also shown sorted correctly.
Regards, Frank
Mikołaj Smoleński staff commented 3 years ago
@modadvisor were @frankvdsm tips helpful?
Keep coding, Mikołaj from MDB
modadvisor commented 3 years ago
i am using mdb vue data table within data table how i can call your function ?
Mikołaj Smoleński staff commented 3 years ago
I guess @frankvdsm fix is applicable only in MDB5. In MDB4 datatable there is no other option than changing date format to YYYY/MM/DD.
Keep coding, Mikołaj from MDB
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB Vue
- MDB Version: MDB4 6.7.2
- Device: PC
- Browser: chrome
- OS: windows 10
- Provided sample code: No
- Provided link: No