Redrawing table after applying filtering by a click on dropdown
Redrawing table after applying filtering by a click on dropdown
User is able to select dates and filter them based on the dates from the datepicker. I have to provide a feature in the drop down menu to so that when the usr clicks "View All Dates" it should display all the data present in the table with initial sorting and filtering applied. I have tried using fnDraw() but it is not working. Please suggest how can this be achieved using dataTables API.
This discussion has been closed.
Replies
oTable.fnFilter('',3);
});[/code]
But table does not return to its original state. I have already used something like above for another column which where I am using fnFilter() to filter the column, there it works perfectly fine.
Please suggest if I am making any mistakes in above code or it needs to be done differently.
Thanks.
I guess you just set your controls to a setting where their values are empty strings (depending on how you wrote your afnFiltering routine)
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var colValue = aData[3];
var dateValue = new Date(colValue);
if ( startDate == "" && endDate == "" )
{
return true;
}
else if(startDate != null && endDate == "") {
if(new Date(startDate) <= dateValue) {
return true;
}
}
else if ( startDate == "" && endDate != "")
{
if(dateValue <= new Date(endDate)) {
return true;
}
}
else if(startDate != null && endDate != null) {
if(new Date(startDate) <= dateValue && dateValue <= new Date(endDate)) {
return true;
}
}
return false;
}
);
[/code]
I think this is a standard code. Apart from trying oTable.fnFilter('',3); for my date column. I have tried methods in these two links:
http://www.datatables.net/forums/discussion/997/fnfilter-how-to-reset-all-filters-without-multiple-requests./p1
http://datatables.net/plug-ins/api#fnFilterClear
But, I am not able to get the original table back with the same sorting applied. Please suggest something to work around this.
Edit: Please suggest any solution for above issue. I have not been able to redraw the table to its original state with initial sorting from drop down option. I have tried the above solutions but could not make it work!! Any help is appreciated.
When a user clicks on View All Dates drop down. I am clearing the start date and end date values and then applying oTable.fnDraw();
[code]
$("#startDate").val("");$("#endDate").val("");
oTable.fnDraw();
[/code]
This worked for me. Thanks.