Multiple Time range filter
Multiple Time range filter
virtuso
Posts: 1Questions: 0Answers: 0
Many thanks for such an awesome plugin.
Hopefully answering this might make it even more versatile...
I am a newbie to Datatables, but enjoying its amazing features.
I am using Datatables 1.9.1 along with ColumnFilterWidgets for multiple column filter which is a marvelous plugin by cyberhobo. Thanks a lot.
A challenge I am facing is to enable multiple time range filters for my "Time" column. I would like to filter my table based on a time ranges that are selected. At present I have some static time ranges like 6AM-9AM, 9AM-12PM, 12PM-3PM. On selecting any of these rows will be filtered for that time ranges.
I have achieved half of my target, I am able to filter one range at a time. But couldn't find a way to make it for multiple ranges those are selected.
This is what I managed.
[code]
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex){
var timeRange = $("#start_time option:selected").val();
if( typeof timeRange != 'undefined' && timeRange != "")
{
timeRange = timeRange.split("-");
var startTime = Date.parse(timeRange[0]).getTime();
var endTime = Date.parse(timeRange[1]).getTime();
var iTime = Date.parse(aData[start_time_coll]).getTime();
if ( !isNaN(iTime) && !isNaN(startTime) && !isNaN(endTime) ) {
if ( iTime >= startTime && iTime < endTime ) {
return true;
} else {
return false;
}
}
}
return true;
});
[/code]
Running out of options, any pointers are highly appreciated.
Thanks.
Hopefully answering this might make it even more versatile...
I am a newbie to Datatables, but enjoying its amazing features.
I am using Datatables 1.9.1 along with ColumnFilterWidgets for multiple column filter which is a marvelous plugin by cyberhobo. Thanks a lot.
A challenge I am facing is to enable multiple time range filters for my "Time" column. I would like to filter my table based on a time ranges that are selected. At present I have some static time ranges like 6AM-9AM, 9AM-12PM, 12PM-3PM. On selecting any of these rows will be filtered for that time ranges.
I have achieved half of my target, I am able to filter one range at a time. But couldn't find a way to make it for multiple ranges those are selected.
This is what I managed.
[code]
$.fn.dataTableExt.afnFiltering.push(
function(oSettings, aData, iDataIndex){
var timeRange = $("#start_time option:selected").val();
if( typeof timeRange != 'undefined' && timeRange != "")
{
timeRange = timeRange.split("-");
var startTime = Date.parse(timeRange[0]).getTime();
var endTime = Date.parse(timeRange[1]).getTime();
var iTime = Date.parse(aData[start_time_coll]).getTime();
if ( !isNaN(iTime) && !isNaN(startTime) && !isNaN(endTime) ) {
if ( iTime >= startTime && iTime < endTime ) {
return true;
} else {
return false;
}
}
}
return true;
});
[/code]
Running out of options, any pointers are highly appreciated.
Thanks.
This discussion has been closed.