0

I am using the footable plugin. The demo explains that we have to specify a data-value either in ticks or the unix timestamp. I have tried both ways and the dates won't sort by date, but still by the first number.

Here's what the demo says: http://fooplugins.com/footable-demos/

"

To sort dates, you must specify that the column is data-type="numeric" and also specify a data-value value for each cell, which can be either the date value in ticks or the unix timestamp value, e.g.

<td data-value="500874333932">15 Nov 1985</td>

"

I've tried the following:

<td data-type="numeric" data-value="2014-07-22">July 22, 2014</td>

<td data-type="numeric" data-value="Tue July 22 2014 09:00:00 GMT-0700 (Pacific Standard Time)">July 22, 2014</td>

<td data-type="numeric" data-value="7/22/2014">July 22, 2014</td>

Tue July 22 2014 09:00:00 GMT-0700 (Pacific Standard Time) is my initial date format I'm receiving.

I've also tried converting my date into unix time, but it didn't work either: 10/17/2014 became 1413558000000 but I don't think that equals 10/17/2014...

 <td data-type="numeric" data-value="1413558000000">July 22, 2014</td>

Any ideas?

eternal
  • 99
  • 1
  • 4
  • 13
  • If my answer doesn't get you going, I'd suggest creating a Plunk to demonstrate what you're seeing. You can use this one as a starting point. (Just make sure you fork it...) http://plnkr.co/edit/OyrImUbDNkRIvAIRekN0 – Jeff Jul 18 '14 at 19:37
  • 1
    Thanks! I ended up using the getTime() method. My problem was I had been putting the data-value in a div instead of a td. – eternal Jul 18 '14 at 22:05

1 Answers1

1

The first thing you need to do is ensure that Footable is working properly. The sorting is just using a simple sort so if the values of data-value are being sorted correctly then the problem isn't with Footable, but with the data.

Next ensure that you're getting a valid value for a given date. It can only have numbers in the value so '11/15/1985' or 'November 15, 1985' won't work.

You'll want to create a Date for a given date and then use the getTime() method. This is what I did for 'November 15, 1985':

new Date(1985, 10, 15).getTime(); (The result is 500886000000)

If you look at the data-value for that date in the demo, you can see that it's pretty close. The difference is due to specifying the time of day or not.

Jeff
  • 2,728
  • 3
  • 24
  • 41