# Hide a table when no data.

**URL:** <https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [July 16, 2020, 9:26am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049 "2020-07-16T09:26:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulkesh001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pulkesh001/32/4194_2.png) [@pulkesh001](https://forum.wixstudio.com/u/pulkesh001)\
**Post date:** [July 16, 2020, 9:26am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/1 "2020-07-16T09:26:38Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/f/4/f45c053e301ecdc5a84772a46893a854c5607834.png)

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

---

<div class="post-metadata">

**Author:** ![anon72313111](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon72313111](https://forum.wixstudio.com/u/anon72313111)\
**Post date:** [July 16, 2020, 9:36am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/2 "2020-07-16T09:36:59Z")

</div>

Hi 🖐

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

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

```

Hope this helps~!  
Ahmad

---

<div class="post-metadata">

**Author:** ![pulkesh001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pulkesh001/32/4194_2.png) [@pulkesh001](https://forum.wixstudio.com/u/pulkesh001)\
**Post date:** [July 16, 2020, 10:05am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/3 "2020-07-16T10:05:07Z")

</div>

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

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/1/e14fce6025f21fe7ec7e42288ecec2239265496f.png)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 16, 2020, 10:30am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/4 "2020-07-16T10:30:50Z")

</div>

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.

```javascript
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…

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

  } );

} );

```

If you have just one row.

---

<div class="post-metadata">

**Author:** ![anon72313111](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@anon72313111](https://forum.wixstudio.com/u/anon72313111)\
**Post date:** [July 16, 2020, 10:31am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/5 "2020-07-16T10:31:31Z")

</div>

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

Query:

```javascript
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

---

<div class="post-metadata">

**Author:** ![pulkesh001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pulkesh001/32/4194_2.png) [@pulkesh001](https://forum.wixstudio.com/u/pulkesh001)\
**Post date:** [July 16, 2020, 11:15am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/6 "2020-07-16T11:15:10Z")

</div>

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

 ![](https://us1.discourse-cdn.com/wix/original/3X/2/3/23f3b0534b27ff46857367884f04e990b2fbe62d.png)

---

<div class="post-metadata">

**Author:** ![pulkesh001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pulkesh001/32/4194_2.png) [@pulkesh001](https://forum.wixstudio.com/u/pulkesh001)\
**Post date:** [July 16, 2020, 11:19am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/7 "2020-07-16T11:19:13Z")

</div>

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](https://www.wix.com/corvid/forum/search/~num~table2) ( the box I want to show when hiding the table is [#box8](https://www.wix.com/corvid/forum/search/~num~box8) )
2. Dataset = [#dynamicDataset](https://www.wix.com/corvid/forum/search/~num~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

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 16, 2020, 11:57am UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/8 "2020-07-16T11:57:53Z")

</div>

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.

```javascript
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.  
[https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#ne](https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#ne)

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…

> **[Hide & show elements | WixWorld](https://russian-dima.wixsite.com/meinewebsite/working-with-buttons)**

---

<div class="post-metadata">

**Author:** ![pulkesh001](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pulkesh001/32/4194_2.png) [@pulkesh001](https://forum.wixstudio.com/u/pulkesh001)\
**Post date:** [July 16, 2020, 1:05pm UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/9 "2020-07-16T13:05:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 16, 2020, 7:12pm UTC](https://forum.wixstudio.com/t/hide-a-table-when-no-data/28049/10 "2020-07-16T19:12:08Z")

</div>

Hello Pulkesh Sharma,

i think you have already found your solution…

> **[Hide an empty row in a table | Velo by Wix](https://community.wix.com/velo/forum/coding-with-velo/hide-an-empty-row-in-a-table)**
>
> Hello
> I want to hide an empty row in the table which is connected to the database.
> The columns of the table are connected with the 4 columns of the database.
> The problem is that when we skip to fill these columns and fill the rest columns in the...

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