How do you clear data store on page refresh?

Hi

I want the data store on a particular page to clear on page refresh - delete all current data in the data store.

How do I do this?

Thanks!

Hi Steven,
Have you checked the dynamic events for App in the App Structure?
There’s a Load event which fires when the page loads - maybe this is what you need?

Thanks @Teodor

Yes I tried that. Set the clear data store on page load. but it still doesn’t clear the data store.

That’s strange, i just tested that and it seems to work. Clears the data on page load.

If this can help, here’s how it looks like this on my page:

<body is="dmx-app" id="index" dmx-on:load="datastore1.clear()">

I have a content page inside a layout and just to test the load it is working I created a variable set to ‘0’ and on load to set to ‘1’.

But its doesn’t seem to be setting the value of the test variable on load and also tried ready. I did a hard refresh still nothing.

this is what it looks on the content page. Maybe because it is inside a layout as below?

<!-- Wappler include head-page="layouts/admin_main" jquery_slim_33="cdn" fontawesome_4="cdn" bootstrap4="local" is="dmx-app" id="list_participants" appconnect="local" dmx-on:load="selectall.clear()" -->

Ah it’s a content page. The App events don’t work on content pages.
What you need here is to create a flow in your content page and add the clear data store as a run step there.
Set the flow to auto run and it will run each time the content page is loaded.

1 Like

ah ok will give that a go and report back.

Anyone else trying to figure out how to trigger an event on page load on content page inside a layout.

Select Page Flow

Create the run step

Set to auto Run

The resulting code in the content page:

<script is="dmx-flow" id="clear_datastore" type="text/dmx-flow" autorun>{
  run: {action: "{{selectall.clear()}}", name: "cleardata"}
}</script>

Thank @Teodor worked and shared the process for anyone else stuck.

2 Likes