next page timer

next page timer

xintellxintell Posts: 13Questions: 0Answers: 0
edited September 2012 in General
well is it possible to make datatable go to next page when the timer runs out?

for example like this

var timer;
clearTimeout(timer);
timer = setTimeout(searchFunctionName, 1000 /* time to wait then go to next page*/);

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Use the fnPageChange API method:

    [code]
    table.fnPageChange('next');
    [/code]

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    edited September 2012
    awesome thanks alot

    well I ended up doing it like this but I cant find out how to get the total number of pages

    [code]$(document).ready(function() {
    oTable = $('#text_field').dataTable({
    "bLengthChange": false,
    "sScrollY": 232,
    "bFilter": false,
    "bSort": false,
    "bInfo": false,
    "bAutoWidth": false,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    });
    ctr=0;
    setInterval(function(){
    if (ctr <= [ TOTAL NUMBER OF PAGE ]){
    oTable.fnPageChange( 'next' );
    ctr=ctr+1;
    }
    else{
    oTable.fnPageChange( 'first' );
    ctr=0;
    }
    },1000);

    } );
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    This plug-in is the best way: http://datatables.net/plug-ins/api#fnPagingInfo

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    edited September 2012
    yeah I did check that one but I have no idea how to get the total value of pages for my if statement
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    [code]
    oTable.fnPagingInfo().iTotalPages
    [/code]

    should be it.

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    well I already tried that like this
    [code]
    max = oTable.fnPagingInfo().iTotalPages;
    ctr=0;
    setInterval(function(){
    if (ctr <= max){
    oTable.fnPageChange( 'next' );
    ctr=ctr+1;
    }
    else{
    oTable.fnPageChange( 'first' );
    ctr=0;
    }
    },1000);
    [/code]
    and like this
    [code]
    if (ctr <= oTable.fnPagingInfo().iTotalPages){
    }
    [/code]
    but it didn't work
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    What is the value of `ctr`? Print it to the console.

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    [code]
    ctr=0; // DEFAULT VALUE OF CTR
    setInterval(function(){
    if (ctr <= [ TOTAL NUMBER OF PAGE ]){
    oTable.fnPageChange( 'next' );
    ctr=ctr+1; // INCREASE VALUE OF CTR
    }
    else{
    oTable.fnPageChange( 'first' );
    ctr=0; // RESETS THE VALUE OF CTR TO 0
    }
    },1000);
    [/code]

    ctr is just a counter that increase each time the page change and resets when it reach the last page
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Oops - sorry. I meant `max` . What is the plug-in telling you are the number of pages - that seems to me to be the point which might be most likely to fail.

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    [code]max = oTable.fnPagingInfo().iTotalPages; // JUST A TEST IF IT CAN GET THE VALUE OF oTable...
    if (ctr <= max){
    }[/code]
    [code]
    if (ctr <= oTable.fnPagingInfo().iTotalPages){ // TEST IF IT CAN WORK LIKE THIS
    }[/code]

    [quote]What is the plug-in telling you are the number of pages - that seems to me to be the point which might be most likely to fail.[/quote]

    I have no idea about this one. I'm just searching for the value that will give me the total number of pages so i think that the plugin you were talking about is irrelevant.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > I'm just searching for the value that will give me the total number of pages

    The plug-in will tell you that.

    Add:

    [code]
    alert( oTable.fnPagingInfo().iTotalPages );
    [/code]

    What is the number that is alerted?

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    edited September 2012
    yes it did but I can't use oTable.fnPagingInfo().iTotalPages for my if statement even if I do it like this
    [code]
    max = oTable.fnPagingInfo().iTotalPages; // MAX IS STILL NULL
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I don't understand. Why can't you use it?

    Here is an example of the plug-in being used to get the number of pages: http://live.datatables.net/ajiliw/edit#javascript,html .

    If you can't get it to work, please link us to a test page showing the problem.

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    thank you for all the help I'll try again
  • xintellxintell Posts: 13Questions: 0Answers: 0
    Is it possible to pause the page change when the page are clicked then wait for like 10 secs then continue the page change?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Sure - you can listen for the 'page' event and alter your code to clear the time out and then start a new one: http://datatables.net/docs/DataTables/1.9.3/#page

    Allan
  • xintellxintell Posts: 13Questions: 0Answers: 0
    Awesome thanks again
This discussion has been closed.