Preserve Component Variables on Navigation

Hi everyone,

I really need to be able to preserve component variables on navigation, which doesn’t seem to be possible. For example, I’m using a data grid component, and I want the selected rows to persist through navigation. Is there any way to do this?

Another example where this would be useful is with search bars, I want whatever my users search to persist in the search bar until they either remove it or close the app.

Thanks!

Save the rows in an array in a variable and then set them again on page change.

But if I go back, my selections will no longer show on the grid.

You need to do the same on page change back. And you need to set your variable to preserve on navigation.

The variable that natively handles the selected rows, and determines which rows are shown as selected, cannot be set in a workflow. So I can make my own variables and keep track of selected rows, but I can’t preserve the displaying of the selection inside the data grid.

I see now it indeed does not show. You might want to do a feature request for this one. In the meantime you can do it like this.

  1. Make a variable and set the values of your selectedRows to it, you can do this on click or something, up to you really. Make it preservable on navigation as I mentioned.

  1. On page change or whatever, you use javascript instead of Change Variable Workflow Action like this
    [DataGrid - selectedRows] = [Dump Array]

Based on my little test, this should work now.
You basically just set the variable with JavaScript instead of WeWeb’s nocode Action, all the rest is same)

Edit: it would be enough to store just parts of the selectedRows data, as I think only some indexes or soemthing like that is making the state “selected”, maybe @aurelie will be able to tell us, I see she is the one who updated it last on github

1 Like

Legend!! Strange that you can set the variable in the JavaScript action but not the change variable action. Would be convenient if we could set component variables to preserve on navigation.

What I ended up doing was creating a workflow that sets a ‘selected_rows’ variable to the data grid’s selected rows anytime the data grid is clicked. I then created a workflow that runs anytime the data grid’s page loads and sets the data grid’s selected rows variable to my ‘selected_rows’ variable. Seems to work so far.

No I’m going to have to do something similar for all of my search bars :sweat_smile:

If you think about it, Workflow actions are just abstractions of the javascript, so if something is not exposed in nocode, you can mostly always force your way with some little code.

Also, if you have a specific text you’re searching for and you would like to store it/transfer it through sessions, you might want to look into query strings.