Filter Date Column by days left
Filter Date Column by days left
I have implemented the status and supplier filters but need to extend the date range filter.
What I would like to have is a filter under the Due column with a drop down box that includes the selections 'Due Tomorrow' and 'Overdue'
If you choose 'Tomorrow' it should only show records that are due in 1 day time
If you choose 'Overdue' it should only show records that are due today or the date has past the due date (duedateID)
http://labdocs.co.uk (u=admin p=admin)
Could anyone point me in the right direction to somehow calculate the difference between today and the due date and implement into the filter accordingly?
What I would like to have is a filter under the Due column with a drop down box that includes the selections 'Due Tomorrow' and 'Overdue'
If you choose 'Tomorrow' it should only show records that are due in 1 day time
If you choose 'Overdue' it should only show records that are due today or the date has past the due date (duedateID)
http://labdocs.co.uk (u=admin p=admin)
Could anyone point me in the right direction to somehow calculate the difference between today and the due date and implement into the filter accordingly?
This discussion has been closed.
Replies
[code]
{ type: "select", values:
[{ "value" : dateString, "label" : "Today (Working)" },
{ "value" : duetomorrowcode, "label" : "Tomorrow" },
{ "value" : overduecode, "label" : "Overdue" }
]},[/code]
In the above example I'm hoping I can simulate the date range function for duetomorrowcode and overduecode
[code]
{
type: "select",
values: [{
"value": dateString,
"label": "Today (Working)"
}, {
"value": duetomorrowcode,
"label": "Tomorrow"
}, {
"value": "",
"label": "Overdue"
}]
},
[/code]
To get the correct date format I've used the moment.js plugin which allows me to easily deduct or add as many days as I need to get a single date.
[code]
var TodaysDateFilter = moment().format("DD/MM/YY");
var Tommorrow = moment().add('days', 1);
var TomorrowsDateFilter = Tommorrow.format("DD/MM/YY");
[/code]
All I need to now is to get the overdue dates working. I'm still not sure how I can include a range of dates as a value but my idea was to show all documents that have a due date of yesterday or less. Or even with a due date that's within a range of 360 days old - which ever is easier.
Are you using a custom filtering plug-in, such as that here: http://datatables.net/release-datatables/examples/plug-ins/range_filtering.html ? I think you will need to, if you aren't, since although today and tomorrow can simply be string matched, dates in the past cannot be. It would need the date to be calculated into a format such as a unix timestamp (presumably that want moment.js's format method is doing?).
If possible, I would recommend using just a single plug-in filter to do all of your filtering for today, tomorrow and in the past, to keep things simple!
One other possible option is that you could have the server render an additional column which could be used to do simple string matching filtering (i.e. the built in filter in DataTables). The server would put a 1 in the column for today, 2 for tomorrow and 3 for the past (for example), then just use fnFilter to filter by the required type.
Regards,
Allan
How would I populate the extra column with the values and how would they update when ii's a new day
> how would they update when ii's a new day
Reload the data in the table (a setInterval to check for a new day perhaps) I think. It would be smoother to use a plug-in filtering method in this regard, but it might also be a little more complicated.
Regards,
Allan
It's a little over my head and I've got a sneaky suspicion I'm going to struggle
but I'll have a look.
Allan