mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
1.28k stars 283 forks source link

load records for grid using data provider #3103

Open teowave opened 9 months ago

teowave commented 9 months ago

Duplicates

Summary

I am trying to load records for grid using data provider. But in my case i need to add additional filter values from external ui components. I found a way to do that by storing them in js file properties that hold data provider logic. But i cant find a way to trigger data provider reload in this case, when my external component filter values change. Is there any ways to do that?

Alternatively i can use direct rows source but then i dont know how to grab grid paging values. Maybe this have easier solution? Thanks.

Examples

No response

Motivation

No response

Search keywords:

Janpot commented 9 months ago

This currently isn't possible yet as all state related to filtering is localized to the datagrid. I see two potential ways we can move forward with this.

  1. We expose the filter model as state on the datagrid and expose onChange/onCommit events on the form components. This will allow you to update the filter model programmatically.
  2. We move the data provider concept at the page level, just like queries/actions and let it hold the filter state. We add UI that lets you bind page state to filter model items. This essentially creates global filter model state and is very similar to how queries/actions already work. I'm slightly more inclined towards this solution. I'll try to write up a feature request for this idea this week.
teowave commented 9 months ago

Thank you for the quick reply and for the attention given to this issue.

Generally I think server-side filtering, like data provider is doing, is an excellent idea - it solves a lot of security and roles and permissions issues, enabling simpler code and system design. However we of course need to have a way to transfer state from the page to the server, as you mentioned in your response

MBilalShafi commented 9 months ago

This currently isn't possible yet as all state related to filtering is localized to the datagrid. I see two potential ways we can move forward with this.

  1. We expose the filter model as state on the datagrid and expose onChange/onCommit events on the form components. This will allow you to update the filter model programmatically.
  2. We move the data provider concept at the page level, just like queries/actions and let it hold the filter state. We add UI that lets you bind page state to filter model items. This essentially creates global filter model state and is very similar to how queries/actions already work. I'm slightly more inclined towards this solution. I'll try to write up a feature request for this idea this week.

Lifting/binding the filterModel state to the page level certainly seems a better way to solve the problem since it will allow other UI elements to manipulate its value and effectively implement filters outside the grid. Something like this one but built using the toolpad UI.

This could hold true for other controlled models like sortModel for example which the users may want to access using some custom UIs.