How can I disable Paging Dynamically?

How can I disable Paging Dynamically?

Geoff_OldingGeoff_Olding Posts: 4Questions: 2Answers: 1
edited May 2018 in Free community support

Hello there.

I am able to disable paging by using the following code:

 $('#geoffstable').dataTable({
            "paging": false
        });

However, I would like to be able to disable it dynamically, e.g. if there is only one page.
I want to do something like:

 $('#geoffstable').dataTable({
            "initComplete": function (settings, json) {
                if ( onePage() ) {
                   var api = this.api();
                   api.paging = false;
                }
        });

This code is wrong, however hopefully it demonstrates what I am trying to do.

Any help greatly appreciated.

Geoff Olding

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 7,242Questions: 0Answers: 1,222
    Answer ✓

    Hi @Geoff,

    You can't disable the paging after the initialisation. I assume you want to get rid of the page controls, so you can be sneaky and just hide them with a jQuery command:

        initComplete: function() {
          if (this.api().page.info().pages === 1) {
            $('#example_paginate').hide();
          }
        }
    

    Live example here.

    Cheers,

    Colin

  • allanallan Posts: 51,008Questions: 1Answers: 7,656 Site admin

    You might be interested in this plug-in.

    It doesn't disable the paging feature as such, but it does hide the UI element from the end user so it looks like it is disabled.

    Allan

  • Geoff_OldingGeoff_Olding Posts: 4Questions: 2Answers: 1

    Many thanks

Sign In or Register to comment.