How to insert Data in the datatable filter

How to insert Data in the datatable filter

joe_majoe_ma Posts: 4Questions: 2Answers: 0

Hello

On a site I am working on I have a data base with addresses. These addresses are being displayed as a table at the front end according to categories. To find data in big tables I use datatable which works very good.

Now I'd like to insert search terms into the filter that come from the search function of the CMS I am using. The following code does exactly what I want, but it seems like it doesn't execute the filter. This is my code:

jQuery(document).ready(function () {
            $("#myTable").DataTable( {          
    paging:   true,
    lengthChange: false,
    pageLength: 5,
    pagingType: "simple_numbers",
    info: false,
    responsive: true,
    language: {
            search: "_INPUT_",
                            zeroRecords:    "Ihre Suche ergab kein Resultat<br>Votre recherche n'a pas reçu des resultats",
            searchPlaceholder: "Tabelle filtern nach … / filtrer le tableau pour …",
            paginate: {
                           previous: '‹',
                           next:     '›'
                    },
                          aria: {
                          paginate: {
                          previous: 'Previous',
                          next:     'Next'
                         }
                }
     }
    });     

And after this I use the following code to insert the search term into the filter:

$(function() {
$.urlParam = function(name) {
var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
if(results==null) {
return null;
} else {
return results[1] || 0;
}
};
var searched = $.urlParam('searched');
if(searched){
$('#myTable_filter input').val(searched);
}
});
});

What do I have to do that the filter executes and the table shows only rows with the search term in it?

Thanks for help.

This discussion has been closed.