Prevent initial datatables load
Prevent initial datatables load
metateck
Posts: 10Questions: 0Answers: 0
[code]
$(document).ready( function () {
oTable = $('#dataTable').dataTable( {
"aaSorting": [],
"sAjaxSource": "some_url",
"aoColumns": [
{'sTitle': 'col1', 'mDataProp': 'mysql_col1'},
{'sTitle': 'col2', 'mDataProp': 'mysql_col2'},
{'sTitle': 'col3', 'mDataProp': 'mysql_col3'},
{'sTitle': 'col4', 'mDataProp': 'mysql_col4'}
],
"oLanguage": {
"sSearch": "Filter records:"
},
"sScrollY": "500px",
"bSortClasses":false,
"sDom": "<'row'<'span5'l><'span5'f>r>t<'row'<'span5'i><'span5'p>>",
"asStripClasses": [],
'fnServerParams': function ( aoData ) {
$.each($('#search').serializeArray(), function(i, keyval_pair) {
console.log(keyval_pair);
aoData.push( keyval_pair );
});
return(false);
}
} );
$('#search').submit(function() {
window.oTable.fnReloadAjax(window.ajax_src);
$('html, body').animate({
scrollTop: $("#dataTable_wrapper").offset().top
}, 500);
return false;
});
});
[/code]
This code all works, but I want the datatables object to initially not fetch any data until the form is submitted. This may even be a very odd bug I have found.
$(document).ready( function () {
oTable = $('#dataTable').dataTable( {
"aaSorting": [],
"sAjaxSource": "some_url",
"aoColumns": [
{'sTitle': 'col1', 'mDataProp': 'mysql_col1'},
{'sTitle': 'col2', 'mDataProp': 'mysql_col2'},
{'sTitle': 'col3', 'mDataProp': 'mysql_col3'},
{'sTitle': 'col4', 'mDataProp': 'mysql_col4'}
],
"oLanguage": {
"sSearch": "Filter records:"
},
"sScrollY": "500px",
"bSortClasses":false,
"sDom": "<'row'<'span5'l><'span5'f>r>t<'row'<'span5'i><'span5'p>>",
"asStripClasses": [],
'fnServerParams': function ( aoData ) {
$.each($('#search').serializeArray(), function(i, keyval_pair) {
console.log(keyval_pair);
aoData.push( keyval_pair );
});
return(false);
}
} );
$('#search').submit(function() {
window.oTable.fnReloadAjax(window.ajax_src);
$('html, body').animate({
scrollTop: $("#dataTable_wrapper").offset().top
}, 500);
return false;
});
});
[/code]
This code all works, but I want the datatables object to initially not fetch any data until the form is submitted. This may even be a very odd bug I have found.
This discussion has been closed.
Replies
This is the test case. I want to have people able to click on links that have search results already populated for their search. I have in the page
[code]
jQuery(function( $ ) {
$( '#inmate_search' ).deserialize( location.search.substr( 1 ), function() {
$('#inmate_search').submit();
});
});
[/code]
But the search is getting submitted twice, which would be tolerable though not ideal. However, what is not acceptable is that datatables has 509 records in it. It is performing the search with no parameters (the query has a limit of 500 on it), and then does the search with parameters and gets 9 results. Notice if you hit search again, you get only 9 results. If I could prevent the initial load, that would solve my problem, but I think the bug I discovered would still be there.