question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting by Date in Correct Format

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
chasegiuntacommented, Oct 16, 2015

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.

1reaction
tmorehousecommented, Oct 17, 2015

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 either 1, 0 or -1 depending on the comparison of a and b. 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 the a and b values into JavaScript date objects or a javascript integer timestamp).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found