DataTables not working when on a page with URL parameters (error: b is null)
DataTables not working when on a page with URL parameters (error: b is null)
Hello everybody,
First of all, this is an awesome plugin. I have been testing it out for a couple of weeks and I am trying to adjust it to my needs. This has been working pretty well- I got server-side processing to work, as well as pipelining, which was amazingly. However, not I ran into a problem that I cannot solve myself.
When I use DataTables table on a page without URL arguments (example: mypage.php) everything works great. However, when I add in any URL parameter, such as "search_type=-15" (the full page would be: mypage.php?search_type=-15) it does not work anymore and the "b is null" error is thrown (line 63 of jquery.dataTables.min.js). My code is pretty standard: (this one does not use pipeling to make debugging simpler)
[code]
$(document).ready(function() {
var oTable = $("#example").dataTable({
//define comulmns
"aoColumnDefs": [
//camp name
{ "aTargets": [0], "bSearchable":true, "bVisible": true, "bSortable":true, "sClass":"" },
//camp state
{ "aTargets" : [1], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp type
{ "aTargets" : [2], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp price
{ "aTargets" : [3], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp description
{ "aTargets" : [4], "bSearchable":true, "bVisible":false, "bSortable":false, "sClass":"" }
],
//ordering
"aaSorting": [[ 0, "asc"]],
//state saving
"bStateSave": false,
//remember duration
"iCookieDuration": 60*60, // 1 hour
// cookie prefix
"sCookiePrefix": "camp_",
//different pagination (full numbers)
"sPaginationType": "full_numbers",
// define class for each row
//"asStripClasses": ['first', 'second', 'third'],
//on redraw call the function that adds details
"fnDrawCallback": function(oSettings){
displayDetails(this);
},
// change the number of records menu
"aLengthMenu": [15, 25, 50, 100],
// setup data gathering from AJAX
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax_scripts/camp_directory_data.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
//this is how you send additiona parameters (search by state, type, etc)
//aoData.push({"name": "more_data", "value": "my_value"});
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
//fnDataTablesPipeline( sSource, aoData, fnCallback );
}
});
//hide the necessary columns to avoid the bug when save state is also set
oTable.fnSetColumnVis(4, false);
});
[/code]
When I look at the Ajax response in Firebug, I see only an empty field. However, when I use the GET link and open a new tab with it, I see all of the data correctly in Json format (validated with Json Lint). Therefore, I am pretty confused about what the problem might be and I have been trying to figure this out all day.
Any help is greatly appreciated!!
First of all, this is an awesome plugin. I have been testing it out for a couple of weeks and I am trying to adjust it to my needs. This has been working pretty well- I got server-side processing to work, as well as pipelining, which was amazingly. However, not I ran into a problem that I cannot solve myself.
When I use DataTables table on a page without URL arguments (example: mypage.php) everything works great. However, when I add in any URL parameter, such as "search_type=-15" (the full page would be: mypage.php?search_type=-15) it does not work anymore and the "b is null" error is thrown (line 63 of jquery.dataTables.min.js). My code is pretty standard: (this one does not use pipeling to make debugging simpler)
[code]
$(document).ready(function() {
var oTable = $("#example").dataTable({
//define comulmns
"aoColumnDefs": [
//camp name
{ "aTargets": [0], "bSearchable":true, "bVisible": true, "bSortable":true, "sClass":"" },
//camp state
{ "aTargets" : [1], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp type
{ "aTargets" : [2], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp price
{ "aTargets" : [3], "bSearchable":true, "bVisible":true, "bSortable":true, "sClass":"" },
//camp description
{ "aTargets" : [4], "bSearchable":true, "bVisible":false, "bSortable":false, "sClass":"" }
],
//ordering
"aaSorting": [[ 0, "asc"]],
//state saving
"bStateSave": false,
//remember duration
"iCookieDuration": 60*60, // 1 hour
// cookie prefix
"sCookiePrefix": "camp_",
//different pagination (full numbers)
"sPaginationType": "full_numbers",
// define class for each row
//"asStripClasses": ['first', 'second', 'third'],
//on redraw call the function that adds details
"fnDrawCallback": function(oSettings){
displayDetails(this);
},
// change the number of records menu
"aLengthMenu": [15, 25, 50, 100],
// setup data gathering from AJAX
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax_scripts/camp_directory_data.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
//this is how you send additiona parameters (search by state, type, etc)
//aoData.push({"name": "more_data", "value": "my_value"});
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
//fnDataTablesPipeline( sSource, aoData, fnCallback );
}
});
//hide the necessary columns to avoid the bug when save state is also set
oTable.fnSetColumnVis(4, false);
});
[/code]
When I look at the Ajax response in Firebug, I see only an empty field. However, when I use the GET link and open a new tab with it, I see all of the data correctly in Json format (validated with Json Lint). Therefore, I am pretty confused about what the problem might be and I have been trying to figure this out all day.
Any help is greatly appreciated!!
This discussion has been closed.
Replies
Just one of those days.
Anyway, awesome plugin, made my life significantly easier!
Sorry for the delay in getting back to you - great to hear you've got it figured out! Love the way you've comment the code above, very clear! I might do something like that on some of the more complex examples.
Regards,
Allan