DataTables server-side processing:DataTable warning:JSON data from server could not be parsed.
DataTables server-side processing:DataTable warning:JSON data from server could not be parsed.
rijz
Posts: 20Questions: 0Answers: 0
This is my table in table.html
[code]
Contact_Name
Job_Title
Email
Phone
6 entries found
[/code]
This is the javascript on the same table.html page
[code]
$(document).ready(function () {
$('#sorting-advanced').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../js/libs/DataTables/datatable.php"
});
});
[/code]
And this is the datatable.php
[code]
<?php
$aColumns = array( 'Contact_Name', 'Job_Title', 'Email', 'Phone');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "Contact_ID";
/* DB table to use */
$sTable = "mytable";
/* Database connection information */
$gaSql['user'] = "*********";
$gaSql['password'] = "*********";
$gaSql['db'] = "*********";
$gaSql['server'] = "*********.com";
/*
* MySQL connection
*/
$gaSql['link'] = mssql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mssql_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 ".$_GET['iDisplayStart'] .", ".
$_GET['iDisplayLength'] ;
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mssql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
But when i run the code it is showing error as
[quote]
DataTable warning(table id='sorting-advanced');
DataTable warning:JSON data from server could not be parsed.This is caused by a JSON formating error.
[/quote]
Can any one please let me know why is it showing the error. Or is there something am missing. Am very new to JSON. Please help me in sorting the issue.
[code]
Contact_Name
Job_Title
Phone
6 entries found
[/code]
This is the javascript on the same table.html page
[code]
$(document).ready(function () {
$('#sorting-advanced').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../js/libs/DataTables/datatable.php"
});
});
[/code]
And this is the datatable.php
[code]
<?php
$aColumns = array( 'Contact_Name', 'Job_Title', 'Email', 'Phone');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "Contact_ID";
/* DB table to use */
$sTable = "mytable";
/* Database connection information */
$gaSql['user'] = "*********";
$gaSql['password'] = "*********";
$gaSql['db'] = "*********";
$gaSql['server'] = "*********.com";
/*
* MySQL connection
*/
$gaSql['link'] = mssql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mssql_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 ".$_GET['iDisplayStart'] .", ".
$_GET['iDisplayLength'] ;
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mssql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
But when i run the code it is showing error as
[quote]
DataTable warning(table id='sorting-advanced');
DataTable warning:JSON data from server could not be parsed.This is caused by a JSON formating error.
[/quote]
Can any one please let me know why is it showing the error. Or is there something am missing. Am very new to JSON. Please help me in sorting the issue.
This discussion has been closed.
Replies
Allan
Allan
Now my question is how to connect to mssql database. Here when i tried to change mysql statement to mssql
[quote] Limit [/quote] to [quote] Top [/quote] there is a problem with the pagination. Is there any way to connect the Mssql database.
Allan
Is it possible to search the datatable based on the select list eg:Industry, Employee etc... and how ??
Please let me know is there a way to use datatable the way it is shown in the image.
Thanks in advance.
Regards
Rijesh
Allan
This is single test string.
[code]
$(document).ready(function () {
var oTable= $('#sorting-advanced').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./js/libs/DataTables/datatable.php",
});
oTable.fnFilter('Information Technology Manager');
[/code]
Can we use something like this
[code]
oTable.fnFilter('USA', 'Information Technology Manager');
[/code]
Please help!!
Regard
Rijesh
You can use it to do a global filter, or a column filter. See the documentation for how to do each.
Allan
This is the select list... designation and the country
[code]
Managment
Engineering
Finance
HR
Legal
Marketing
Operations
Sales
USA
CANADA
UNITED KINGDOM
GERMANY
FRANCE
AUSTRALIA
NORWAY
SWEDEN
[/code]
this is the ajax...
[code]
$('select').change(function () {
var designation = $("#designation").val();
var revenue = $("#revenue").val();
var employees = $("#employees").val();
var industry = $("#industry").val();
var country = $("#country").val();
var oTable= $('#sorting-advanced').dataTable({
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"bRetrieve": true,
"sAjaxSource": "./js/libs/DataTables/buildlist.php",
"aoColumns": [
{ "sName": "Contact_Name" },
{ "sName": "Job_Title" },
{ "sName": "Email" },
{ "sName": "Phone" },
{ "sName": "Revenue" },
{ "sName": "Employees" },
{ "sName": "Industry" },
{ "sName": "Country" }
]
});
//oTable.fnFilter('Information Technology Manager');
oTable.fnMultiFilter({ "Job_Title": designation, "Revenue": revenue, "Employees": employees,"Country": country, "Industry": industry });
});
[/code]
But again this is not working for multiple selections on select list . Will it work with fnMultifilter??
What am i missing.
Please help, and thank you very much for your kind support Allan.
Regards,
Rijesh
Allan
This is the server side script i am using..
[code]
<?php
$aColumns = array( 'Contact_Name', 'Job_Title', 'Email', 'Phone','Revenue','Employees','Industry','Country');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "Contact_ID";
/* DB table to use */
$sTable = "mytable";
/* Database connection information */
$gaSql['user'] = "*********";
$gaSql['password'] = "*********";
$gaSql['db'] = "*********";
$gaSql['server'] = "*********.com";
/*
* MySQL connection
*/
$gaSql['link'] = mssql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mssql_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 ".$_GET['iDisplayStart'] .", ".
$_GET['iDisplayLength'] ;
}
/*
* Ordering
*/
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mssql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i
[/code]
This is the script am using:
[code]
$('select').change(function () {
var designation = $("#designation").val();
var revenue = $("#revenue").val();
var employees = $("#employees").val();
var industry = $("#industry").val();
var country = $("#country").val();
var oTable = $('#sorting-advanced').dataTable({
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"bRetrieve": true,
"sAjaxSource": "./js/libs/DataTables/buildlist.php",
"aoColumns": [
{ "sName": "Contact_Name" },
{ "sName": "Job_Title" },
{ "sName": "Email" },
{ "sName": "Phone" },
{ "sName": "Revenue" },
{ "sName": "Employees" },
{ "sName": "Industry" },
{ "sName": "Country" }
]
});
// oTable.fnFilter(search)
oTable.fnMultiFilter({ "Job_Title": designation, "Revenue": revenue, "Employees": employees, "Country": country, "Industry": industry });
});
[/code]
What is that am missing in the above code? Please let me know or give me a link to refer.
Regards,
Rijesh
I almost went through whole of documentation. But i could not find anything where the same column is filtered with multiple keyword. Is it after all possible in datatable?
for example: the industry column need to be filtered using the select list , and the selection can be multiple. Like Retail and software. Based on that the datatable should show up.
I tried fnfilter and fnMultifilter , i got result using fnMultifilter but only for single selection of select list.
The image is here http://pms.leadsys.co/Untitled%2065.jpg
For multiple selection of select list it is not working.
Here is the image http://pms.leadsys.co/Untitled%2064.jpg
The php script and the jquery i used is pasted on the above post.
How should crack this? What is the way to sort this out. Please help!!!
Thanks,
Regards
Rijesh
Yes it is possible, but not it is not in DataTables. If you were using client-side processing then it would work automatically - however, as it is, you'll need to modify the scripts you posted above to do multi-word matching on column filters. Probably not a trivial change I'm afraid.
Allan
Please
Regards,
Rijesh
Allan
Would you be able to help me out from this ? I would really appreciate it.
Regards,
Rijesh
Thanks Allan for your kind support.
Regards
Rijesh