Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to filter dates #187

Open
amitavadeb opened this issue Aug 17, 2018 · 3 comments
Open

unable to filter dates #187

amitavadeb opened this issue Aug 17, 2018 · 3 comments

Comments

@amitavadeb
Copy link

amitavadeb commented Aug 17, 2018

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
Copy link
Owner

ratiw commented Aug 18, 2018

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

@amitavadeb
Copy link
Author

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
Copy link
Owner

ratiw commented Aug 21, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants