Hiding table if server action returns no resul

I have a table that lists balances based on an a selected input. Two cells on the table are calculated fields using values from the other columns of each row. The server action includes two queries that calculate three sums (load_total, ordered_total, and invoiced_total). When the result for those sums come back with no results, the calculated fields display “invalid amount” as expected. However, the cells containing the sums still displays the previous values displayed when they should be “no result”. How can I have NO RESULT or $0.00 displayed if no result was found in the server action queries?

I’m somewhat new to Wappler so please provide details instructions. Thanks so much for your help!

Do you mean it shows the values as per your previously selected input value?

Yes. For instance, the values displayed for load total, ordered total, and invoiced total in the uploaded image are the correct values for the previous input. There should be no values for the input of F03E16.

Please try adding a key in the repeat element. In your case this is the tbody element. Select an unique ID from your repeat region there - such as record ID.
This should fix your issue.

My table was created using BS4 table generator and I don’t see a repeat region where I can select a unique ID. Can you please explain in more detail? Thanks.

Yes, in App Structure you will see the table. Expand it and you will see the repeat region, which is applied on tbody element.
When you click it, you will see the repeat properties.

Teodor,

I’m sorry. I gave you the wrong info. The table does not have a repeat. The sums and calculated values were just added into the table cells using dynamic attributes (value) picker.

Can you please post the table code here?

<table class="table text-center table-bordered">

                                <thead class="thead-dark">

                                    <tr>

                                        <th scope="col">Load Total</th>

                                        <th scope="col">Ordered Total</th>

                                        <th scope="col">Invoiced Total</th>

                                        <th scope="col">Balance (after orders)</th>

                                        <th scope="col">Balance (after invoices)</th>

                                    </tr>

                                </thead>

                                <tbody>

                                    <tr>

                                        <td dmx-text="costcenter_balances.data.load_totals.load_totals.toNumber().formatCurrency('$', '.', ',', 2)">Mark</td>

                                        <td dmx-text="costcenter_balances.data.order_totals.ordered_total.toNumber().formatCurrency('$', '.', ',', 2)">Otto</td>

                                        <td dmx-text="costcenter_balances.data.order_totals.invoiced_total.toNumber().formatCurrency('$', '.', ',', 2)">@mdo</td>

                                        <td dmx-text="(costcenter_balances.data.load_totals.load_totals.toNumber() - costcenter_balances.data.order_totals.ordered_total.toNumber()).formatCurrency('$', '.', ',', 2)" class="bg-info">@mdo</td>

                                        <td dmx-text="(costcenter_balances.data.load_totals.load_totals.toNumber() - costcenter_balances.data.order_totals.invoiced_total.toNumber()).formatCurrency('$', '.', ',', 2)" class="bg-info">@mdo</td>

                                    </tr>

                                </tbody>

                            </table>

How are you filtering the data source (database query)?

For the load total and sums queries, I have a “contains” $GET_ variable that is pointed to the select input field.

Is there a way to display something like “NO DATA” on the load totals cell if no value was returned in the query?

Try using the default formatter like:

<td dmx-text="costcenter_balances.data.load_totals.load_totals.toNumber().formatCurrency('$', '.', ',', 2).default('NO DATA')"></td>

That works! Thanks for your help. I did the same for the ordered and invoiced totals. Thanks much for your help, Teodor!

1 Like