No change on filter

No change on filter

scpfiscpfi Posts: 4Questions: 2Answers: 0

Greetings,
I am trying to filter the results shown in my datatable when choosing from a dropdown (on a certain value of the dropdown, eg. 'All' the whole table should be visible again - thus the table_data.search('').draw();
I am using the code below and although the true and false values are returned correctly there is no change on the datatable.
Do you have any pieces of advice?
Thanks

$("#timeframe_data_dropdown li a").click(function(){
        var table_data = $('#bot_table_data').DataTable();
        if ($(this).text() != 'All') {
            var date_ago = moment().format('DD.MM.YY, HH:mm');

            if ("Last 7 days" == $(this).text()) {
                date_ago = moment().subtract(7, 'days');
            }
            else if ("Last 30 days" == $(this).text()) {
                date_ago = moment().subtract(30, 'days');
            }
            else if ("Last 90 days" == $(this).text()) {
                date_ago = moment().subtract(90, 'days');
            }
            else if ("Last 180 days" == $(this).text()) {
                date_ago = moment().subtract(180, 'days');
            }
            else {
                date_ago = moment().subtract(365, 'days');
            }
            alert(date_ago);
            var filteredData = table_data.column(11).data().filter(function ( value, index ) {
                var date_dataset = moment(value, 'DD.MM.YY, HH:mm');
                return date_ago.isBefore(date_dataset);
            } ).draw();
        }
        else {
            table_data.search('').draw();
        }
    });

This question has an accepted answers - jump to answer

Answers

  • scpfiscpfi Posts: 4Questions: 2Answers: 0

    I have read online that it might be impossible to use search and filter functions (and $.fn.dataTable.ext.search.push) when loading data using ajax calls.
    Is that true?

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    Yes, if you are using server side processing. If you have server side processing enabled then the search functionality is the performed by your server script.

    However if you don't have SSP enabled you can use the above with ajax loading of the data. If this is the case then please post a link to your page or a test case so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.