My individual column searching (text inputs) are not searching on their columns, but only on the ID
My individual column searching (text inputs) are not searching on their columns, but only on the ID
mmcnair80
Posts: 83Questions: 21Answers: 7
I have the table rendering correctly and am using fixed header and footer, and server side processing. I've added the Individual column searching (text inputs) based on what I found here. However, no matter which filter box I type into all of them search only on the ID (the first column) and not on the column that they are under.
Here's how I initialize the DatatTable:
$(document).ready(function () {
// Setup - add a text input to each footer cell
$('#DataTable tfoot th').each(function () {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
});
var table = $('#DataTable').DataTable({
"lengthMenu" : [[25, 50, 75, 100, 150], [25, 50, 75, 100, 150]],
"dom" : '<"top"Bilp<"clear">>rt<"bottom"ip<"clear">>',
"buttons" : [{
extend : 'collection',
text : 'Selection',
buttons : ['selectAll', 'selectNone']
}, {
extend : 'collection',
text : 'Export',
buttons : ['excel', 'csv', 'pdf']
}
],
"fixedHeader" : {
header : true,
footer : true
},
"select" : true,
"processing" : true,
"serverSide" : true,
"ajax" : {
"url" : "./ServerSide.php",
"type": "POST"
},
initComplete: function() {
var api = this.api();
// Apply the search
api.columns().every(function() {
var that = this;
$('input', this.footer()).on('keyup change', function() {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
}
});
});
Am I doing something wrong with this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The example you used does not have server-side processing.
As you are using serverSide processing, your searching (and sorting) should be handled by your own server-side script. With serverSide enabled, DataTables will just present what it's given.
@tangerine Right, the example doesn't use Server-side processing, but I was only using that example for the filtering.
Here is my ServerSide.php file:
```php
<?php
include 'Helper/PageName.php';
include 'DBConn.php'; //echo "<br>Testing";
$headings = array();
$hsql = "select Headings from TableHeadings where TableName = '$TableName' order by Id";
$getHeadings = $conn->query($hsql);
$rHeadings = $getHeadings->fetchALL(PDO::FETCH_ASSOC);
$CountHeadings = count($rHeadings);
$tsqlHeadings = '';
$ColumnHeader = array();
for ($row = 0; $row < $CountHeadings; $row++)
{
if($rHeadings[$row]["Headings"] <> "Edit")
{
$headings[$row] = $rHeadings[$row]["Headings"];
}
}
foreach($headings as $index => $columnName)
{
$ColumnHeader[] = array('db'=>$columnName,'dt'=>$index);
}
$table = $SQLTableName;
$primaryKey = 'id';
$request = array();
$_POST['PageName'] = $Page;
$request = $_POST;
require('FilterSort.class.php');
echo json_encode(FilterSort::complex($request,$sqlConnect,$table,$primaryKey,$ColumnHeader));
<?php > ``` ?>And here is my FilterSort.class.php (a modified version of the ssp.class.php file):
```php
<?php
class FilterSort
{
static function data_output($columns,$data)
{
$out = array();
for($i=0,$ien=count($data);$i<$ien;$i++)
{
$row = array();
for($j=0,$jen=count($columns);$j<$jen;$j++)
{
$column = $columns[$j];
if(isset($column['Formatter']))
{
$row[$column['dt']] = $column'Formatter';
}
else
{
$row[$column['dt']] = $data[$i][$columns[$j]['db']];
}
}
$out[] = $row;
}
return $out;
}
}
<?php > ``` ?>I have found the error.
All of my column names are surrounded by []. So I found that I had to add that to the
array_search
in the filter function like this:updated to: