Redrawing table after applying filtering by a click on dropdown

Redrawing table after applying filtering by a click on dropdown

kunalkunal Posts: 16Questions: 0Answers: 0
edited November 2011 in General
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.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    remove the filters you have applied with the date picker. I think you just send an empty string to your fnFilter() call for that column.
  • kunalkunal Posts: 16Questions: 0Answers: 0
    edited November 2011
    @fbas: For filtering the dates lying in range using datepicker I have modified the $.fn.dataTableExt.afnFiltering.push() method based on my date format in the column. I have tried using fnFilter() method like this: [code]$('#allDates').click( function () {
    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.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    is this based on http://www.datatables.net/examples/plug-ins/range_filtering.html ?

    I guess you just set your controls to a setting where their values are empty strings (depending on how you wrote your afnFiltering routine)
  • kunalkunal Posts: 16Questions: 0Answers: 0
    Yes, the implementation is similar to the example in the link. I am not so well versed with data tables and have been going through alot of forum posts to solve my problems. I have used the following code for $.fn.dataTableExt.afnFiltering.push() method
    [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.
  • kunalkunal Posts: 16Questions: 0Answers: 0
    edited November 2011
    Any suggestions anyone?

    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.
  • kunalkunal Posts: 16Questions: 0Answers: 0
    edited November 2011
    I have been able to fix this issue by using a hack. It might be helpful for others who may not get the above two utilities to work.

    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.
This discussion has been closed.