drvic10k / bootstrap-sortable

adding sorting ability to bootstrap table
MIT License
513 stars 131 forks source link

data-value being overwritten for date columns #110

Closed ericnh closed 5 years ago

ericnh commented 7 years ago

I have a datetime sortable column displayed in this format: 02/01/17 12:44pm UTC-0800 (PST)

Which is defined in the data-dateformat attribute as: "MM/DD/YY hh:mma UTCZZ (zz)"

That works great. The problem is that not every cell has an available date. When the attribute is missing from the row the string 'N/A' is printed out into that cell instead. This seems to be interpreted by moment to somehow mean today:

missingDate = moment('N/A', "MM/DD/YY hh:mma UTCZZ (zz)");
missingDate.format("YYYY/MM/DD/HH/mm/ss")
>"2017/02/01/00/00/00"

This creates a problem with sorting because the 'N/A' rows get placed between rows with a date greater than or equal to the current date and dates less than the current date.

I tried to manually set the data-value for these rows with an arbitrarily early date data-value="0001/01/01/00/00/00". But this seems to get overwritten. When I look at the dom the data-value for these 'N/A' rows appears as data-value="2017/02/01/00/00/00"

Any help would be appreciated. Thank you!

drvic10k commented 7 years ago

I wanted to try it, so I went to moment page: https://momentjs.com/ and tried your example in console there

moment('N/A', "MM/DD/YY hh:mma UTCZZ (zz)").format("YYYY/MM/DD/HH/mm/ss")

result is "Invalid date"

so the solution might be updating moment.js is it possible in your environment to put newest moment.js there ant check if it works better?