KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Save filter #1769

Closed Epitello opened this topic on on Dec 16, 2020 - 4 comments

Epitello commented on Dec 16, 2020

Hello, I woul like to save filter created in a first document to use them in other document by one click for recreate same dataTable. Do you have any example how i can do that ? And i don't find any solution to use stateSaveCallback, do you have any exemple for this to ? thanks by advance

Sebastian Morales commented on Dec 17, 2020

You would need to use javascript to capture the current DataTables' filter string with this method:

    //javascript
    var filter = currentTable.search();

Then pass it to your new page (via either GET, POST or ajax parameters) and after the new DataTables is loaded just apply the search for it

    //javascript
    newTable.search(filter);
Epitello commented on Dec 17, 2020

Hello, This not solve my problem because i use custom filter and the search method doesn't catch it.

function applyFilters(){
    //récupère le tableau voulu
    let table = $('#globalTable').DataTable();
    
    //fonction permettant de comparé chaque ligne du tableau avec le filtre
    $.fn.dataTable.ext.search.push(
        function( settings, data, dataIndex ) {
            let matriculeNb = $('#matriculeNb').val()
            let operator = $('#operator').val()

            //indique quelle données utiliser pour la comparaison 
            //(le numéro correspond au numéro de la colonne. le compte du numéro de colonne commence à partir de 0)
            let matricule = data[2]

            if(matriculeNb == ""){
                return true
            }else{
                if(matricule > matriculeNb){
                    return true
                }else{
                    return false
                }
            }
            
        }
    );
    
    table.draw()
}
Sebastian Morales commented on Dec 18, 2020

Well, so instead of catching filters from DataTables' input just catch them from your custom inputs:

            //current page
            let matriculeNb = $('#matriculeNb').val();
            let operator = $('#operator').val();

            //pass these input values to your new page

            //new page
            //perform filtering with the passed input values
Epitello commented on Jan 4, 2021

It's work fine thanks

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

DataGrid