datatables How to get the search value entered in Datatables programmatically? Example

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

This is the code to filter the Datatables [1.10.7] by value programmatically, you can find it on official documentation.

function setFilterValue(datatable, value){
    if(datatable !== undefined){
        datatable
            .columns(0)
            .search(value)
            .draw();
    }    
}

This is the code to get the value by the previous search.

function getFilterValue(datatable){
    var value;
    if(datatable !== undefined){
        value = datatable
                    .settings()[0]
                    .oSavedState
                    .columns[0]
                    .search.search;
    }
    return value;
}

This approach is useful when you have the cache active ("stateSave": true) and you need to know the previous search value after reloaded the page.



Got any datatables Question?