How to use in where clause when populating datatables
How to use in where clause when populating datatables
Hello
I have seen this code for trying to send customer_id as a where clause to my datatables server side page
```javascript
var customer_id = "<?php echo $customer_id; ?>";
var table = $('#branchesdt').DataTable( {
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"columns": [
{ "data": "branch_name" },
{ "data": "branch_email" },
{ "data": "tel" },
{ "data": "fax" },
{ "data": "address1" },
{ "data": "address2" },
{ "data": "town" },
{ "data": "city" },
{ "data": "county" },
{ "data": "postcode" },
{ "data": "country_name" },
{"data": null,
"defaultContent": "<button>Click!</button>"
}
],
"sAjaxSource": "DataTables/branches_dt.php",
"fnServerData": function ( sSource, aoData) {
/* Add some data to send to the source, and send as 'POST' */
aoData.push( {"name": "customer_id", "value": customer_id} );
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"cache": false,
"data": aoData,
"success": function(json) {
/* Do whatever additional processing you want on the callback,
then tell DataTables */
fnCallback(json);
}
} );
}
}
);
```
It doesnt work the table just shows processing
Thanks in advance for your help
Answers
Or is there anyway to add a where clause here directly
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
it seems to be in the $_GET array
This is the reponse i get from the server but nothing is filtered and nothing is bound to the table
<br />
<b>Notice</b>: Undefined index: columns in <b>C:\xampp\htdocs\cpe\DataTables\ssp.class.php</b> on line <b>159</b><br />
<br />
<b>Notice</b>: Undefined index: draw in <b>C:\xampp\htdocs\cpe\DataTables\ssp.class.php</b> on line <b>245</b><br />
{"draw":0,"recordsTotal":2,"recordsFiltered":2,"data":[{"DT_RowId":"row_1","branch_name":"Head Office","branch_email":null,"tel":null,"fax":null,"address1":null,"address2":null,"town":null,"city":null,"county":null,"postcode":null,"country_name":"UK"},{"DT_RowId":"row_2","branch_name":"Head Office","branch_email":null,"tel":null,"fax":null,"address1":null,"address2":null,"town":null,"city":null,"county":null,"postcode":null,"country_name":"UK"}]}
I turned the error reporting off and the data is not displayed in the table. However it is not filtered by the where clase
More data
Here is what is sent to the server
http://localhost/cpe/DataTables/branches_dt.php?sEcho=1&iColumns=12&sColumns=%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C%2C&iDisplayStart=0&iDisplayLength=10&mDataProp_0=branch_name&sSearch_0=&bRegex_0=false&bSearchable_0=true&bSortable_0=true&mDataProp_1=branch_email&sSearch_1=&bRegex_1=false&bSearchable_1=true&bSortable_1=true&mDataProp_2=tel&sSearch_2=&bRegex_2=false&bSearchable_2=true&bSortable_2=true&mDataProp_3=fax&sSearch_3=&bRegex_3=false&bSearchable_3=true&bSortable_3=true&mDataProp_4=address1&sSearch_4=&bRegex_4=false&bSearchable_4=true&bSortable_4=true&mDataProp_5=address2&sSearch_5=&bRegex_5=false&bSearchable_5=true&bSortable_5=true&mDataProp_6=town&sSearch_6=&bRegex_6=false&bSearchable_6=true&bSortable_6=true&mDataProp_7=city&sSearch_7=&bRegex_7=false&bSearchable_7=true&bSortable_7=true&mDataProp_8=county&sSearch_8=&bRegex_8=false&bSearchable_8=true&bSortable_8=true&mDataProp_9=postcode&sSearch_9=&bRegex_9=false&bSearchable_9=true&bSortable_9=true&mDataProp_10=country_name&sSearch_10=&bRegex_10=false&bSearchable_10=true&bSortable_10=true&mDataProp_11=&sSearch_11=&bRegex_11=false&bSearchable_11=true&bSortable_11=true&sSearch=&bRegex=false&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&customer_id=1&_=1399900461553
It just shows all customers and not where customerID = 1