Is it possible to get the "active" pagination length when the stateSave is true?

Is it possible to get the "active" pagination length when the stateSave is true?

PepayuPepayu Posts: 11Questions: 3Answers: 0

I have something like this

 buttons: [
     {
         text: 'Show',
         attr: { id: 'showBtnPlaceholder' },
         action: function (e, dt, node, config) {

         }
     },
     {
         
         text: '25',
         attr: { id: 'pagination25' },
         action: function (e, dt, node, config) {
             toy= true;
             table.page.len(25).draw();
         }
     },
     {
         text: '50',
         attr: { id: 'pagination50' },
         action: function (e, dt, node, config) {
             toy= true;
             table.page.len(50).draw();
         }
     },

It is working as intended, basically i did a button type "show number in page" type instead of dropdown due to requirement.

However, another requirement is that they want to see what is the current pagination being used if it is 25 or 50, so this is on page load or when clicked and i will play with it in jquery/javascript

I'm thinking if there is a way to put the "active" something like in a radiobutton on the ACTIVE page.length?

Thanks!

Replies

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    The page.len() API is both a getter and setter. Use it to get the current page length.

    Kevin

  • PepayuPepayu Posts: 11Questions: 3Answers: 0

    Hi @kthorngren, how I can initially get the value of page.len() upon pageload?

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    Use initComplete or ready() to get the page length after Datatables initializes.

    Kevin

  • PepayuPepayu Posts: 11Questions: 3Answers: 0

    Hi @kthorngren i did create this:

         var table = $('#productTable').DataTable({
                initComplete: function (settings, json) {
                  
                    xx =  table.page.len();
           
    
                },
    

    but:

    error states
    Cannot read properties of undefined (reading 'page')
    Please note that this is the same var table from my inside my table as my question

  • PepayuPepayu Posts: 11Questions: 3Answers: 0

    Hi again @kthorngren

    Did try the ready()

          table.ready(function () {
            xx = table.page.len();
            alert(xx);
    });
    

    and it worked! thank you! but why does the initComplete not working? Just curious

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    The problem is that the API hasn't been assigned to the table variable yet as the call to DataTable(...) hasn't competed. You can get an instance of the API using this.api(), for example:

           initComplete: function (settings, json) {
              
               xx =  this.api().page.len();
       
     
           },
    

    Kevin

Sign In or Register to comment.