How to disable a draw function on search

How to disable a draw function on search

atatayloratataylor Posts: 35Questions: 7Answers: 0

I am using the following code to place a page number next to a headline, using the data from the pagination. The headline is league. So, when on page 2 the headline reads league 2 and so on. It is working great. I am looking for a way to hide the added number when the search box is used because the number is no longer relevant as the table repopulates when the new data is displayed.
Not sure if what I am trying to do is possible or not, so any help would be welcome.

table.on( 'draw', function () {
    var info = table.page.info();
$('#tableInfo').html(
    'Sales League '+(info.page+1));
} );

Replies

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    You could also check the number of rows in your info variable. If recordsDisplay isn't equal to recordsTotal, then you know the table is being filtered.

    Colin

  • atatayloratataylor Posts: 35Questions: 7Answers: 0

    Thanks Colin I will work on that idea

  • atatayloratataylor Posts: 35Questions: 7Answers: 0

    Following Colins advice and doing some research I have added the following code below the initial code posted earlier in the discussion. But it does not work, am I on the right track anyone?

    $("input").keyup(function(){
    var info = table.page.info();
    var info2 = table.pages.info();
    
    if(info !==info2){
        $('#tableInfo').hide();
    
    }else
    $('#tableInfo').show();
     
    });
    
  • colincolin Posts: 15,118Questions: 1Answers: 2,583
    edited July 2021

    I think you missed the point of my message, I meant something like:

    $("input").keyup(function(){
    var info = table.page.info();
     
    if(info.recordsDisplay !==info.recordsTotal){
        $('#tableInfo').hide();
     
    }else
    $('#tableInfo').show();
      
    });
    

    Colin

  • atatayloratataylor Posts: 35Questions: 7Answers: 0

    Hi Colin Thanks, you are right I did miss the point of your message thanks for persevering with me.
    I eventually came up with this:

    $("input").keyup(function() {
        if (this.value == '') {
            $("#tableInfo").hide();
        } else {
            $("#tableInfo").show();
        }
    });
    
    

    But it feels a bit hackney as it involves splitting the words from the numbers in html and putting them in separate h tags. Then aligning them in a div with css.
    So, your solution is much more elegant and works great so I will use your code. Thanks for your help and advice.

Sign In or Register to comment.