Assistance with fnPageChange...
Assistance with fnPageChange...
Hello,
What I am trying to do is have the datatable point the user to page one on each new search (i.e. each time the user clicks submit):
I tried to attach the fnPageChange to the onlick event, but cannot get it to work:
jsp:
[code]onclick="setDatalistPageOne()"[/code]
js:
[code]function setDatalistPageOne() {
var dataTable = $(#dataList).dataTable();
dataTable.fnPageChange('first', false);[/code]
My datatable gets initialised in the "$(document).ready(function() {" event. Eg:
[code]
$(document).ready(function() {
var dataTableInit = $("#dataListSearchSubject").dataTable( {
"bAutoWidth": true,
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
etc. etc etc. ,
"fnServerData": function ( sSource, aoData, fnCallback ) {
*some code in here*
}
});
} );
[/code]
Should i be calling fnChangePage in a similar way to the "fnServerData" - should it be outside the initialisation but still in the document.ready or should it be in an onclick like I have, but I am doing it wrong? I am a beginner to DataTables and this is some existing (working) code I have to maintain...
NOTE: I do need bStateSave to be true; so setting that to false won't solve my issue..
Thanks heaps
What I am trying to do is have the datatable point the user to page one on each new search (i.e. each time the user clicks submit):
I tried to attach the fnPageChange to the onlick event, but cannot get it to work:
jsp:
[code]onclick="setDatalistPageOne()"[/code]
js:
[code]function setDatalistPageOne() {
var dataTable = $(#dataList).dataTable();
dataTable.fnPageChange('first', false);[/code]
My datatable gets initialised in the "$(document).ready(function() {" event. Eg:
[code]
$(document).ready(function() {
var dataTableInit = $("#dataListSearchSubject").dataTable( {
"bAutoWidth": true,
"bProcessing": true,
"bServerSide": true,
"bStateSave": true,
etc. etc etc. ,
"fnServerData": function ( sSource, aoData, fnCallback ) {
*some code in here*
}
});
} );
[/code]
Should i be calling fnChangePage in a similar way to the "fnServerData" - should it be outside the initialisation but still in the document.ready or should it be in an onclick like I have, but I am doing it wrong? I am a beginner to DataTables and this is some existing (working) code I have to maintain...
NOTE: I do need bStateSave to be true; so setting that to false won't solve my issue..
Thanks heaps
This discussion has been closed.
Replies
"dataTableInit.fnPageChange('first',false);"
behaviour is as follows:
1. Search for a people with name 'BOB'
2. returns several pages of people containing Bob in their name
3. Go to page 2 of results
4. Search for a specific Bob (should only return one result)
5. Page is set as 1, however a note is displayed saying no search results found (which is incorrect cause I know this person exists)
6. If I then just click search again, the search is performed and the correct record is displayed on page 1
not sure why, ill keep investigating and hope someone posts :(
[code]"iDisplayStart" : 0,[/code]
Allan
Passing true did the the trick...
I assumed the initialisation was doing a draw, so I didn't think I would want to redraw it.. (i.e. perform two draws for one search)
Allan