DataGrid not updating

Hi,

I created a simple page where I placed a datagrid to show some data ("products"). One column is called "IsActive" and is of type bool.

In also added a page property of type bool, initialized this with "true" and used it in a filter when querying the data for the grid on page load to filter if only those products shall be shown that have IsActive=true or IsActive=false.

That works fine.

Now I want to be able to change the page property at runtime.

I added a "Switch" (aka "Pill Button") to the page and in the "Clicked" event, I set the value of the page property to the current value of the switch. That also works.

However, the datagrid does not reflect the changes. How do I update the gird? Invoking the Reload method did not show an effect and executing grid0.Reload() also did nothing. The page property has changed when I click on the switch but the query that gets the products seems not to be executed again and/or the gird that shows the data is not updated.

This is certainly something very simple but I did not find a way to update the query when the filter parameter changes.

Any help would be appreciated!

Best regards,

Joe

You need to invoke again the data source method which you use to populate the data grid. This is probably done int the Load event of your page.

Hi @korchev!
Thanks for your reply. That was also what I assumed. Indeed I initially query the data with the filter in the Page Load event. But how do I reinvoke this method when the button is clicked? I tried the "Reload" method in the click event of the button but that does not have any effect. Or do you I have to copy the entire code from the Page Load event to the click event of the button?
In the sample video tutorials on your page (the filter as you type sample), the date source is not loaded again and only the grid.Load() method is called. Is it possible that this video is out of date and that the process of updating data on the form has changed since then?

Any help that points me into the right direction would be great!

Thanks and best regards,

Joe

Use Execute C# action with Code set to await Load()

What video are you referring to?

Thanks for your reply. That was, what I initially tried, but it has no effect. Here is a screenshot that shows all the settings that I have applied:


From my understanding, this should work, but it does not. The data and the grid remain the same when I click on the switch. Any ideas?

The video I referred to in my previous post: Create a search screen - YouTube - this seems to be Angular, but as I understand it, the grid is relaoded here and not the data source...

Unfortunately I don't have any ideas. You can try debugging your code to trace the code execution.

The Angular DataGrid behaves in a different way. This article sounds similar to what you are after: Filter by multiple fields as you type (Blazor)

1 Like

Thanks a lot! Debugging with VS was a good idea: The reason why nothing happens is quite logically: Since in the Page Load I also set the inital value for my filter Page Property to "False", this code is also executed when I call Load() to update the data. So, as a result, every time the data source is queried, the filter property is "false". That is why nothing changed on the screen.

I was able to solve this by removing the initial assignment. But in case I want to provide an initial value for the page property: Is there a condition I can apply to the set property action in page load? E.g. something like "only, if the page is loaded for the first time" or something similar?

Thanks for your help!

Best regards,

 Joe

Instead of calling the Load method (which could indeed have side effects) you can just use Invoke data source method getProducts with the required parameter and set the getProducts result property. Basically duplicate the Load method without the initial assignment of ShowOnlyActiveProducts.