Filtering Array of Objects by attribute and not by array Index
Filtering Array of Objects by attribute and not by array Index
I want to create a date range filter that can be applied to a number of datatables. The problem I am having is even though I am passing
in my aaData value as an array of objects by the time I get to the filter function it is in an array. This wont work because the index of the date value in the array is different in the various dataTables throughout my application and I would much rather be able to do it via dot notation on an attribute something like this.
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = document.getElementById('start-datepicker').value;
var iMax = document.getElementById('end-datepicker').value;
// Create Minimum Date Object
var iMinDate = new Date(iMin);
// Create Maximum Date Object
var iMaxDate = new Date(iMax);
// Create Date Column Object
var iDateStr = aData.date;
var iDate = new Date(iDateStr);
if ( iMinDate < iDate && iDate < iMaxDate )
{
return true;
}
return false;
}
);
[/code]
in my aaData value as an array of objects by the time I get to the filter function it is in an array. This wont work because the index of the date value in the array is different in the various dataTables throughout my application and I would much rather be able to do it via dot notation on an attribute something like this.
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = document.getElementById('start-datepicker').value;
var iMax = document.getElementById('end-datepicker').value;
// Create Minimum Date Object
var iMinDate = new Date(iMin);
// Create Maximum Date Object
var iMaxDate = new Date(iMax);
// Create Date Column Object
var iDateStr = aData.date;
var iDate = new Date(iDateStr);
if ( iMinDate < iDate && iDate < iMaxDate )
{
return true;
}
return false;
}
);
[/code]
This discussion has been closed.
Replies
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = document.getElementById('start-datepicker').value;
var iMax = document.getElementById('end-datepicker').value;
// Create Minimum Date Object
var iMinDate = new Date(iMin);
// Create Maximum Date Object
var iMaxDate = new Date(iMax);
// Create Date Column Object
var rowData = oSettings.aoData[iDataIndex]._aData;
var iDateStr = rowData.date;
var iDate = new Date(iDateStr);
if ( iMinDate < iDate && iDate < iMaxDate )
{
return true;
}
return false;
}
);
[/code]
Allan