Recover filter values

Recover filter values

flash.teamflash.team Posts: 2Questions: 1Answers: 0

I would like to save all filter values ​​from both columns and the general one. My goal is to save the filters of the datatable to be able to do background processes with php according to the selected criteria. How can I get the filter values ​​in tfoot from the DataTable object?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    Answer ✓

    You can use search(), column().search() and/or columns().search() to get the current search terms. The inputs you place in the footer are independent of Datatables and Datatables doesn't know anything about them not has API's to access them. If you want the values from the inputs you can use standard Javascript or jQuery techniques to retrieve them.

    Kevin

  • flash.teamflash.team Posts: 2Questions: 1Answers: 0

    Thanks Kevin for your explanation!!
    So as I understand, If I need to send the column name and the search value, a code like this one is "more or less" correct. What do you think about it?

                var columns = [];
                var settings = oTable.settings()[0];
                settings.aoColumns.forEach(function(aoColumn) {
                    columns[aoColumn.idx]=
                        {
                        'name': aoColumn.name,
                        'value': ''
                        };
                });
    
                var table = document.getElementById('table_projects'),
                    footRow = table.getElementsByTagName('tfoot'),
                    i, j, cells, searchValue;
    
                if ( footRow.length === 1) {
                    cells = footRow[0].getElementsByTagName('th');
                    for (i = 0, j = cells.length; i < j; ++i) {
                        cell = cells[i].getElementsByTagName('input');
                        if(cell.length > 0) {
                            searchValue = cell[0].value;
                            columns[i].value = searchValue;
                            console.log(searchValue);
                        }
    
                    }
                }
                console.log(columns);
    
This discussion has been closed.