0

I have a page (table.php) with a script for Datatables that is calling "table_data.php" as the sAjaxSource.

I'm trying to add a single drop down filter above the datatables table, to control what set of data the datatable starts with. The problem is, the Ajax data file (table_data.php) does not have access to the POST variables and I don't see a method of passing variables to it through the sAjaxSource call of the dataTable({}) instantiation script.

How would I call the ajax data file and pass the POST variable from the main page form drop down, so that the Ajax data file has the POST variable?

Basically, I'm just trying to add this into the SQL query on the ajax data file:

        if (!empty($location_post_variable)){
            $query .= " AND a.location= '" . $location_post_variable. "'";
        } else {
            $query .= " AND a.location= '" . $location_default. "'";
        }   

Thanks. Perhaps there's a better way of doing this like maybe adding a single drop down filter to the datatables object itself, to control what set of data it starts with?

Reno
  • 2,962
  • 9
  • 41
  • 68

1 Answers1

0

We can use Datatables ajax.data option to add additional data to the request, or to modify the data object being submitted to server if required.

To work with new and refresh data input we need to use ajax.data as a function otherwise it will initialized as a static object which will evaluated only once.

See rest of my answer and working demo on this question:

Reinitialise DataTable

mike85
  • 621
  • 4
  • 8