• Resolved YuppiDu

    (@andreavecchi71)


    Hi Peter!

    I created a publication for showing on a page a certain table content; to do that, I used the [wpdataaccess] shortcode.

    When the table is empty (no rows) I would like to avoid to print the table header/footer having the classical “no records found” sentence inside.

    In this case, I would prefer the shortcode not showing anything at all..

    Is it possible to reach this goal by using some trick?

    Thks a lot

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Andrea,

    That’s tricky! ??

    There are two ways you can do this:
    (1) Display the table and hide if no data is found
    (2) Hide the table at startup and make it visible when data is found

    For the first (simplest) option add this javascript to your page:

    var table = $('#your_table_id').DataTable();
    if ( table.data().count() ) {
        table.parent().hide();
    }

    // your_table_id = table_name + pub_id

    You will see some flickering (elements popup and disappear). If you don’t like that, try option 2…

    For the second option you need to add some css to your page that hides your table and div wrapper (parent element of your table) and change the javascript to work the other way round.

    var table = $('#your_table_id').DataTable();
    if ( table.data().count() ) {
        table.show();
        table.parent().show();
    }

    Make sure you handle the div wrapper and the table both, otherwise you will see some flickering alike option 1.

    Good luck! And please let me know if this works… ??

    Best regards,
    Peter

    Thread Starter YuppiDu

    (@andreavecchi71)

    TKS a lot Peter, the second option works for me!

    Maybe you can also consider a special flag for managing this behavior in the next plugin releases ??

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Great! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to avoid to print empty tables’ is closed to new replies.