# Loader in table while changing parameters

**URL:** <https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 17, 2024, 3:36pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959 "2024-06-17T15:36:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 17, 2024, 3:36pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/1 "2024-06-17T15:36:39Z")

</div>

Hello!

I have a table with a named query that has a date parameter, when I change the parameter the data load on the table but take a while as it´s large.

There is a quick way to show a loader while the new data is loading?

What I´m using now is a emptyMessage.noData.text

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e017b37d15f5d496ee4fcbeb0c74469dafab1955.png)

wich shows the message while there is no data at all but not when there is data.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 17, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/2 "2024-06-17T15:42:37Z")

</div>

Add an onChange event to the date selection to wipe the table's data before it triggers the reload.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 17, 2024, 3:53pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/3 "2024-06-17T15:53:28Z")

</div>

Hello!

I´m trying adding to my change script something like:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/f/ef2f26e83b252a507f9fa785272ae1b4829168bc.png)

```python
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    if event.propertyName == "props.value":

        table = self.getSibling("Table_0")

        headers = [] # No columns
        data = [] # No data rows
        emptyDataset = system.dataset.toDataSet(headers, data)

        table.props.data = emptyDataset
  
        if hasattr(self.getParent(), 'updateTableData'):
            self.getParent().updateTableData()

```

but not working...

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 17, 2024, 3:57pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/4 "2024-06-17T15:57:25Z")

</div>

Can you show the query ? That seems way too long for just a query, even for a large amount of data.

You don't need to filter on property name in perspective, the script will only trigger for this property.

And as usual, "not working" is not a sufficient error message. We need details.  
But... if you just want to wipe the table clean, why is the script so complicated ?  
Something like `self.getSibling('table').props.data = None` should work

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 17, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/5 "2024-06-17T15:58:58Z")

</div>

Tip: should your column header be **kWh Used** (not "kW Used"). Don't confuse power and energy. Same for your other columns, I suspect.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 17, 2024, 3:59pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/6 "2024-06-17T15:59:47Z")

</div>

> [@Alejandro\_Alaco](#):
>
> `if event.propertyName == "props.value"`

That is something you do in Vision, not Perspective. In the latter, change events are attached to just the one property.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [June 17, 2024, 4:02pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/7 "2024-06-17T16:02:30Z")

</div>

What everyone else has said, plus, I'm not sure why you are referencing a sibling, simply:

```python
self.props.data = None

```

...should work.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 17, 2024, 4:03pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/8 "2024-06-17T16:03:52Z")

</div>

This is the table with the date parameter wich filter with the date input

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/c/4cd9dc2b297f0070c244acc227a310a6cdfd4824.png)

The data is very latge, the query

```python
WITH MAXKW AS (
    SELECT 
        TS.CODIGO, TS.ORDEN_DNF, 
        MAX(TM.KWGEN) AS MAX_TOTAL_HIST
    FROM T_MEDIDAS_TE TM
    JOIN T_Sede TS ON TM.id_sede = TS.id_sede
    WHERE TM.timestamp BETWEEN ADD_MONTHS(TRUNC(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')), -12) AND TRUNC(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')) + INTERVAL '1' YEAR - INTERVAL '1' SECOND
      AND TS.ORDEN_DNF IS NOT NULL
    GROUP BY TS.Codigo, TS.ORDEN_DNF
),					
HISTMAXKW AS (
    SELECT 
        TS.CODIGO, TS.ORDEN_DNF, 
        MAX(TM.KWGEN) AS HISTMAX
    FROM T_MEDIDAS_TE TM
    JOIN T_Sede TS ON TM.id_sede = TS.id_sede
    WHERE TS.ORDEN_DNF IS NOT NULL
    GROUP BY TS.Codigo, TS.ORDEN_DNF
),
AVGKW AS (
    SELECT 
        TS.CODIGO, TS.ORDEN_DNF,
        TS.COD_DNF,
        TS.KWCON AS KWCON,
        TS.KWLIM AS KWLIM,
        AVG(TM.KWGEN) AS AVG_KW_GEN, 
        MAX(TM.KWGEN) AS MAX_KW_PERIOD,
        AVG(TM.KWCLT) AS AVG_KW_CLT,
        MAX(TM.KWCLT) AS MAX_KW_CLT,
        AVG(TM.KWIT) AS AVG_KW_IT,
        MAX(TM.KWIT) AS MAX_KW_IT,
        TS.DNF_BAT AS DNF,
        TS.DNF_BAT_10 AS DNF10,
        TS.PRVDNF AS PRVDNF,
        MAX(TM.PENEJE) KEEP (DENSE_RANK FIRST ORDER BY TM.TIMESTAMP DESC) AS "PENEJE",
        0 AS RAMPA
    FROM T_MEDIDAS_TE TM 
    JOIN T_Sede TS ON TM.id_sede = TS.id_sede
    WHERE TM.timestamp >= TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')
      AND TM.timestamp < TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS') + INTERVAL '1' YEAR
      AND TS.ORDEN_DNF IS NOT NULL
    GROUP BY 
        TO_CHAR(TM.timestamp, 'YYYY'), 
        TO_CHAR(TM.timestamp, 'IW'), 
        TS.Codigo, 
        TS.ORDEN_DNF, 
        TS.KWCON, 
        TS.KWLIM, 
        TS.COD_DNF, 
        TS.DNF_BAT, 
        TS.DNF_BAT_10, 
        TS.PRVDNF
)
SELECT 
    STM.CODIGO AS "CODE",
    STM.COD_DNF AS "DNF code",
    STM.KWCON AS "kW Cont.", 
    STM.KWLIM AS "kW Lim.",
    STM.AVG_KW_GEN AS "kW Used", 

....

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 17, 2024, 4:05pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/9 "2024-06-17T16:05:20Z")

</div>

Because the change script is not on the table itself, but on the date selector.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 17, 2024, 4:09pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/10 "2024-06-17T16:09:29Z")

</div>

```python
WHERE TM.timestamp BETWEEN 
    ADD_MONTHS(
        TRUNC(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')), -12
    ) AND 
        TRUNC(TO_DATE(:startdate, 'YYYY-MM-DD HH24:MI:SS')) 
        + INTERVAL '1' YEAR - INTERVAL '1' SECOND ...

```

Are you saving datetime as strings? (Bad)

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 17, 2024, 5:24pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/11 "2024-06-17T17:24:49Z")

</div>

Should I fix that?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 17, 2024, 5:31pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/12 "2024-06-17T17:31:12Z")

</div>

Dates and timestamps should always be stored as DateTime type. They can be indexed easily and filtered quickly. You also have the ability to store in UTC so that you don't have (as much) trouble with daylight savings, etc.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [June 17, 2024, 5:32pm UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/13 "2024-06-17T17:32:31Z")

</div>

Ok, will try the conversion, thanks Transistor

I was doing a work around for the date string

```python
def transform(self, value, quality, timestamp):
  
    import system

system.date.format
    formatted_date = system.date.format(value, 'yyyy-MM-dd HH:mm:ss')

    return formatted_date

```

will try do it straight

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 18, 2024, 8:12am UTC](https://forum.inductiveautomation.com/t/loader-in-table-while-changing-parameters/91959/14 "2024-06-18T08:12:42Z")

</div>

Don't import `system`. It's already available without importing it.

And Transistor is 200% right: use the appropriate data type.
