ratiw / vue-table

data table simplify! -- vuetable is a Vue.js component that will automatically request (JSON) data from the server and display them nicely in html table with swappable/extensible pagination component.
MIT License
1.83k stars 303 forks source link

unable to filter dates #187

Open amitavadeb opened 6 years ago

amitavadeb commented 6 years ago

hi,

i am using vue-table and i am trying to filter a date column which i am unable to do.

//options options: { toMomentFormat: 'YYYY-MM-DD' }

//templates templates: { jobdate: function (row) { moment.locale("en-gb") var new_date = new Date(row.job_date); return moment(new_date.getTime()).format("L") } }

the problem is: i am unable to filter the dates. my server is sending dates as '2018-07-05 11:56:54 AM' format. the dates on my date column is viewed as '2018-07-05 11:56:54 AM' format.

Thanks

ratiw commented 6 years ago

It looks more like you're having a problem with formatting, not really filtering. Try moment's documentation first.

amitavadeb commented 6 years ago

the code which i have posted is having format mis-match but no matter what i do; even if i correct the format, the filter doesnt work.

what i found is: the example of vue-table posts dates as JS object which is different from what i am getting from my server and if i make my dates as JS objects, i am unable to format it on the view front.

i am stuck here. any example? i want to create my view as "Aug 13, 2018" and want to filter dates between 2 ranges using vue-tables bootstrap-datepicker.

thanks

ratiw commented 6 years ago

@amitavadeb I'm still not quite clear about your problem, especially the filter one. I'm not sure if I will be able to answer you correctly or not. But if your server stores data in the YYYY-MM-DD format (usually called ISO format), you will have to query it using that format. On the front end, if you want to display it differently, you will first have to convert it to a generic format first, and then re-format it the way you want to display it.

If the date format sent from the server is '2011-01-12', you can tell moment to parse it correctly into its generic format like so,

  var dt = moment('2011-01-12', 'YYYY-MM-DD')

Then, you can tell moment to format it into different format like so,

  dt.format('MMMM Do YYYY')   // January 12th 2011

When you want to send the date back for your server side to process, you have to use the date format that your server understand (in this example, YYYY-MM-DD). I hope that make sense.