Hide a table when no data.

Hi,
I want to hide the # Table2 when there is no data with its respected field connected to the database (Member Database). Instead, I want to show # box 8.

And when the respected fields are populated, I want to show the # table2 instead of # box 8.

Can anybody help with this, please?

Thanks in advance
Pulkesh

Hi :raised_hand_with_fingers_splayed:

You check how many rows the table has, then hide it if it was empty.

if ($w("#myTable").rows.length === 0) {
    $w("#myTable").hide();
}

Hope this helps~!
Ahmad

Hi Ahmed,

Thanks for reaching back so quickly.
It tried with the same code.
Unfortunately, It did not work.

For your information, these are the four fields to which the data of the table is connected.
What I am trying to do is that to make the table hide, when the these fields are emplty.

Thanks again for helping.
Pulkesh

Hello Pulkesh Sharma,

it would be better, when you would also show your code. You do not give enough input, to work with. Where is your code?

Also you do not tell us, in which cases exactly you want to hide your table…

a) hide my table if just one of the colum-entries is EMPTY.
b) hide my table if all of the 4 column-entries is EMPTY.

I do not know if Ahmad’s suggested code will work for you. But this suggestion was given by lack of given informations.

if ($w("#myTable").rows.length === 0) {
    $w("#myTable").hide();
}

This code just look to the rows of the table and counts them.

In your case i would check the entries in the database and then react to their values.
If you use a “dataset” so i would suggest this one…

$w.onReady( () => {
  $w("#myDataset").onReady( () => {
    let itemObj = $w("#myDataset").getCurrentItem();

  } );

} );

If you have just one row.

You can check the fields if they’re empty or not when quering the database, or when filtering the dataset.

Query:

wixData.query('member-database')
    .ne('projectName', '')
    .ne('totalSquare', '')
    .ne('totalCommission', '')
    .ne('commessionReceived', '')
    .find()
    .then((members) => {
        if (members.length > 0) {
            // handle case where you have matching members
        } else {
            // handle case where there's no matching members
        }         
    })

The filtering process is almost the same.

Hope this helps~
Ahmad

Hello Russian Dima,
Sorry for the incomplete information.

Sorry, but I am new to coding and don’t know much about this.

Can you help me with the complete code?

The idea is to hide the table when there is no data in the database for these 4 columns.
I exactly want the option b of yours
b) hide my table if all of the 4 column-entries is EMPTY.

For your information:

  1. the table I want to hide is #table2 ( the box I want to show when hiding the table is #box8)
  2. Dataset = #dynamicDataset.
    The Four Columns what I connected with the table is:
    (Field Name) - (Field Key)
    Project Name - projectNameCommissionStats
    Total Sq.ft. - totalsqftCommissionStats
    Total Commission - totalCommissionCommissionStats
    Commission Received - commissionReceivedCommissionStats

Thanks for your helping nature.
Pulkesh

Hi Ahmad,
Sorry to disturb you again.

Sorry, but I am new to coding and don’t know much about this. Can you help me with the complete code?
The idea is to hide the table when there is no data in the database for these 4 columns.

For your information:

  1. the table I want to hide is #table2 ( the box I want to show when hiding the table is #box8 )
  2. Dataset = #dynamicDataset . The Four Columns what I connected with the table is: (Field Name) - (Field Key)
    Project Name - projectNameCommissionStats
    Total Sq.ft. - totalsqftCommissionStats
    Total Commission - totalCommissionCommissionStats
    Commission Received - commissionReceivedCommissionStats

Thanks for your helping nature.
Pulkesh

Hello again,

there are several of variations how you can solve your problem.

i think Ahmad gave you already a very good example, how to do it.
Here some more informations for you…

Create a query, add a equals filter, and run it

Another version of how to do… (using “eq”) almost the same as Ahmads suggestion but inverted.

import wixData from 'wix-data';

wixData.query("Member Database")
  .eq('projectName', '')
  .eq('totalSquare', '')
  .eq('totalCommission', '')
  .eq('commessionReceived', '')
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
      let items = results.items;
      let firstItem = items[0];
      let totalCount = results.totalCount;
     // let pageSize = results.pageSize;
     // let currentPage = results.currentPage;
     // let totalPages = results.totalPages;
     // let hasNext = results.hasNext();
     // let hasPrev = results.hasPrev();
     // let length = results.length;
     // let query = results.query;
     
      console.log(results)
      console.log(items)
      console.log(firstItem)
      console.log(totalCount)
      
      //Try to use CONSOLE-LOGGING to see every result.
      //With this technique you will be able to understand your CODE better!
   
      // Your Code here when all 4 of your columns has no entry 
            
      
    } else {
      // create your CODE here, if one of the 4 entries is not empty.
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

You will have to modify/optimize the code a little bit for your own needs.
This one is just an example.

As i already mentioned in my comments inside the given CODE, try to use CONSOLE-LOGs, this will help you in future to understand your own code better. You can use it also for DEBUGGING.

Also take a look into the CORVID-REFERENCE-API !!! You can find all that stuff there.

If you do not know, how to hide elemets, or you are unsure with your created code,
take a look at this example here. You will see how it works on a live example…

https://russian-dima.wixsite.com/meinewebsite/working-with-buttons

hello Russian Dima, Thanks for such a wonderful explanation.

Can you also please help me with the code for if statement. to hide the row in the table if the 4 columns have no entry.

I want to hide the specific row in the table which has no entry in the database.

Thanks
Pulkesh

Hello Pulkesh Sharma,

i think you have already found your solution…

nnect all your opened posts which belongs to your issue. I saw, that you already have several posts.