The search functionality of dataTable is not working.
The search functionality of dataTable is not working.
$('.dataTable').dataTable({
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"bEscapeRegex": true,
"iDisplayLength": 25,
"searching": false,
"sPaginationType": "full_numbers",
"sAjaxSource": <?php echo "\"$ajaxUrl\"" ?>
});
$ajaxParams = array('cluster' => $cluster, 'job' => $job, 'module' => $module, 'product' => $product, 'arch' => $arch, 'level' => $level);
$ajaxUrl = "job_query.php?" . fnEncodeParameterList($ajaxParams);
This is how i am rendering the table. The search funtionality is not working.
Answers
Does your server-side script implement server-side processing? You've enabled server-side processing, so that script will need to do all the search and ordering required.
Out of interest, why are you using the legacy Hungarian notation (e.g.
bAutoWidth
rather thanautoWidth
)? I haven't used the legacy notation in the documentation for this site for a long time now.Allan
Hey Allan,
What i an doing here is a bug fix, i.e. trying to make the search functionality work. This is a part of a very old website that was used by very few people(which is why the legacy notations), but all of a sudden has become useful to a lot more.
This was my server side script earlier:
<?php
include("connect.php");
include("functions.php");
// Fetch query parameters.
$cluster = $_GET["cluster"];
$job = $_GET["job"];
// Set LIMIT clause.
$limitClause = fnGetLimitClause();
// Set ORDER BY clause.
$orderByClause = fnGetOrderByClause();
// Set WHERE clause.
$whereClause = "WHERE cluster.name = '$cluster' AND job.name = '$job' ";
// Set HAVING filter clause.
$filterClause = fnGetFilterClause(fnGetFilterColumns());
// Set GROUP BY clause.
$groupByClause = fnGetGroupByClause(fnGetGroupByColumns());
// Receive and process search parameter.
**$searchValue = $_GET['search']['value'];
$searchCondition = "";
if (!empty($searchValue)) {
// Add conditions to match against relevant columns for search.
$searchCondition = "AND (module.name LIKE '%$searchValue%' OR product.name LIKE '%$searchValue%' OR architecture.name LIKE '%$searchValue%' OR level.name LIKE '%$searchValue%' OR srcFile.name LIKE '%$searchValue%')";
}
// Modify the WHERE clause to include the search condition.
$whereClause .= $searchCondition;**
// Fetch the base query string.
$baseQuery = fnGetBaseQuery();
// Submit the query without the filter to get the total row count.
$totalRowCount = fnGetRowCount("$baseQuery $whereClause $groupByClause");
// Submit the query with the filter to get the filtered row count.
$filteredRowCount = fnGetRowCount("$baseQuery $whereClause $groupByClause $filterClause");
// Submit the complete query one last time to fetch the data.
$result = fnGetQueryResult("$baseQuery $whereClause $groupByClause $filterClause $orderByClause $limitClause");
// Create the Ajax response message.
$output = fnCreateAjaxResponse($totalRowCount, $filteredRowCount, $result);
echo $output;
// Release mySQL resources.
mysqli_free_result($result);
mysqli_close($conn);
// ... (rest of your functions remain unchanged)
```
cant figure out whats wrong with it. any sort of help is much appreciated.
What is the response from the server? Does it include any error messages?
I'd suggest outputting the generated SQL statement and seeing if you can run that directly against the database. My guess is that is results in invalid SQL (although I'm not immediately seeing where).
Allan