eherve / mongoose-datatable

Server side dataTable request support for mongoose
MIT License
42 stars 28 forks source link

Date filtering #51

Closed stang1013 closed 6 years ago

stang1013 commented 6 years ago

Hi Eric, I'm trying to find good mongoose datatable plugin, yours are much mature than others, noticed no updated couple years, not sure if you are still watching. What I want to do is that, I have a field with Date type, when I do filtering, say I input "2018" in the data table search box, your mongoose-datatable won't filter out all 2018 items I expected, I understand that you are using old isDate to check date parsed "2018" which return false. any easy fix which send back the expected result?

Best Regards Steven

eherve commented 6 years ago

Hi Steven,

Thanks for using this plugin. I still follow questions and issues on this plugin, and try to answer as soon as possible.

Regarding your question, date are tricky to use for filtering and not well documented sorry. The best way would be to override the date condition handler https://github.com/eherve/mongoose-datatable#condition-handlers and to build your mongodb search.

To select the condition handler I base the selection on the mongoose field type, so if it is a Date it will trigger the date condition handler.

I hope this will help you.

Regards,

stang1013 commented 6 years ago

Thanks a lot, I'll try it out.

Regards.

stang1013 commented 6 years ago

Your suggestion helps. great appreciated. BTW, if I want to implement the column summarize, ig, one column with all numbers, want to summarize all the column items filtered in different pages(same page column items summarize are easy ), any suggestion?

Regards Steven

eherve commented 6 years ago

Hi,

You want to sum all of one column data from all filtered results and expose it ? Since this plugin is sending back only the page data you'll have to do it on your server. I would do it manually with an aggregate and a reduce on mongodb (https://docs.mongodb.com/manual/reference/operator/aggregation/reduce/)

I hope this helps

stang1013 commented 6 years ago

Thanks Eric for the suggestion, I updated the plugin library to satisfy my needs, in the rest before schema.dataTable call, user can define the column's to be summarized req.query.search.sumcol= ['amount']; In the fnDrawCallback of the data-table client, this.api().ajax.json() will have sumCol object which contains the summarize of all columns requested, in my case, it is only amount column: this.api().ajax.json().sumCol.amount.

If you need the one I updated, I can either send the updated code to you or check it in directly.