Sorting by Date in Correct Format
See original GitHub issueI just need to sort my table by the values in a date colume. Currently, I’m echoing the dates in YYYY-MM-DD
, but I can echo the date values in whatever format needed, but ultimately want them displayed in MM/DD/YYYY
or M/D/YYYY
in Bootstrap Table. Is there a JSFiddle anywhere for how I would go about sorting dates in one of those two formats?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Sort by dates - Microsoft Support
Sort by dates · Drag down the column to select the dates you want to sort. · Click Home tab > arrow under...
Read more >How to Sort by Date in Excel - MakeUseOf
Excel offers a few different methods to sort your data by ascending or descending date.
Read more >SORT DATE Functions with Examples - Tech Agilist
Using SORT DATE Functions you can dynamically insert the date, like 'yyyy-mm-dd' or any format instead of a constant date like '2021-01-01'.
Read more >How to sort by date in Excel: chronologically, by month, auto sort
How to sort dates in chronological order · Select the dates you want to sort chronologically. · On the Home tab, in the...
Read more >Excel Date Sorting Explained: How to Sort by Date, Auto Sort ...
Select Sort Oldest to Newest under Sort & Filter on the Home Tab's Formats group. Alternatively, you can use the Sort & Filter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So I ended up placing the
<span class="hidden">YYYY-MM-DD</span>
before echoing the desired format. Seems hacky but works. Curious as to what the correct way to do this is.By default, columns are sorted alphabetically by the content in the cell (which may include HTML formatting).
You can specify a custom JavaScript sorter function for a column with your dates in it.
Check out http://issues.wenzhixin.net.cn/bootstrap-table/#options/custom-sort.html
and https://github.com/wenzhixin/bootstrap-table-examples/blob/master/options/custom-sort.html for an example of using acustom sorter
The sorter function take two cell values to compare:
mySorter(a, b)
. The function returns either1
,0
or-1
depending on the comparison ofa
andb
. In our case you would need to convert the formatted date into a format that can be compared in the way you want. (maybe turn thea
andb
values into JavaScript date objects or a javascript integer timestamp).