Custom search in datatables server_processing.php
Custom search in datatables server_processing.php
I want to provide an interface to a user for advance search where they can search in datatable.
here is what i have tried but it is not working.
var oTable =$('#example111').dataTable( {
"iDisplayLength": 10,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
// Bold the grade for all 'A' grade browsers
if ( aData[0] != 0 )
{
$('td:eq(0)', nRow).html( '' );
}
if ( aData[5] != 0 )
{
// $('td:eq(4)', nRow).html( 'A' ); // You can add your link here!!
$('td:eq(5)', nRow).html( '' );
}
return nRow;
},
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "CompanyName",
"value": "Debenhams" } );
},
"oLanguage": {
"sSearch": "Search all columns:"
}
} );
here is my server_processing.php code
<?php
/*
* Script: DataTables server-side script for PHP and MySQL
* Copyright: 2010 - Allan Jardine
* License: GPL v2 or BSD (3-point)
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
//$aColumns = array( 'engine', 'browser', 'platform', 'version', 'grade' );
$aColumns = array('is_active','CompanyName', 'email', 'phone_no', 'web_address','id' );
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "inf_company";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "mydb";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
aoData.push({ "name": "CompanyName","value": "Debenhams" });
CompanyName is table field and Debenhams is value there exists This search is not working
here is what i have tried but it is not working.
var oTable =$('#example111').dataTable( {
"iDisplayLength": 10,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing.php",
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
// Bold the grade for all 'A' grade browsers
if ( aData[0] != 0 )
{
$('td:eq(0)', nRow).html( '' );
}
if ( aData[5] != 0 )
{
// $('td:eq(4)', nRow).html( 'A' ); // You can add your link here!!
$('td:eq(5)', nRow).html( '' );
}
return nRow;
},
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "CompanyName",
"value": "Debenhams" } );
},
"oLanguage": {
"sSearch": "Search all columns:"
}
} );
here is my server_processing.php code
<?php
/*
* Script: DataTables server-side script for PHP and MySQL
* Copyright: 2010 - Allan Jardine
* License: GPL v2 or BSD (3-point)
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
//$aColumns = array( 'engine', 'browser', 'platform', 'version', 'grade' );
$aColumns = array('is_active','CompanyName', 'email', 'phone_no', 'web_address','id' );
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "inf_company";
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "";
$gaSql['db'] = "mydb";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
aoData.push({ "name": "CompanyName","value": "Debenhams" });
CompanyName is table field and Debenhams is value there exists This search is not working
This discussion has been closed.