-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Replace prop.state
with prop.initialState
#2848
Conversation
prop.state
with prop.initialState
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@flaviendelangle I check the PR and for me, it makes perfect sense to have this separation and to hide the Regarding the docs - we can have a single page explaining the |
Yes |
I will document the |
I only implemented the initial states that were used in our tests, docs or stories (
filter
,sorting
andpreferencePanel
), I can implement others (pagination
,selection
,density
) but I think starting small is not a bad idea.Goals
Remove
prop.state
without loosing the ability to open the preference panel on mountThe current
prop.state
is dangerous to use on most sub-states because it forces the user to also pass the internal values (for instance thesortedRows
forstate.sorting
).Moreover, if we allow people to "control" the whole state, then the whole state structure is public API and therefore we should never do breaking change on it between major releases. And that is an important constraints that I think we should not have, especially for a (
prop.state
) that is not really usable.The goal here is to limit this external state to a subset of the state on which we will make no breaking change between major releases and to leave all the internals private.
Allow to initialize the filter / pagination, ... without controlling them
The following example talks about the filters but the same thing applies to other controllable states.
On the current version, either you do not set any filter on mount, or you have to fully control the filter. If you only pass a
filterModel
and noonFilterModelChange
, you have a broken UI because you can try to change the values of the input / selects but they will never be applied.We should probably disable the filter panel when we are in this scenario in another PR.
You have an example of this breaking UI is the 1st example of the filtering doc : https://mui.com/components/data-grid/filtering/#basic-filter
But I think it is a 100% valid use case to want to give an initial filter without controlling it. This is now possible by giving an initial state
Ultimately I propose we have the following behaviors
prop.filterModel
andprop.onFilterModelChange
defined : the filtering UI is editable and the state is controlledprop.filterModel
defined butprop.onFilterModelChange
not defined : the filtering UI is not editable and the state is controlledprop.initialState.filter.filterModel
defined : the filtering UI is editable, the state is not controlled but initialized with the prop valueprop.filterModel
andprop.initialState.filter.filterModel
not defined, the filtering UI is editable and initialized with the default valueThe same applies to other controllable models.
Prepare the state export
The value taken by
initialState
should be compatible with what is exported by the futureexportState
method.In both cases we want a subset of the states (we do not want to export the internal rows representation for instance).
The users would then be able to do something like
Internal behavior
useGridStateInit
)Docs
I have a few questions here about how we want to organize our doc examples @m4theushw @DanailH
Do we want to add a section in the filter and sorting pages to tell how to initialize those states. Or do we want a single centralized section in a new page ?
Do we want our doc examples to use
initialState
or the control model when we only want to show a static value (not to show how the control state works). The filter example usesprop.filterModel
withoutprop.onFilterModelChange
so they are broken and I migrated them toprop.initialState
. But sorting examples always define bothprop.sortModel
andprop.onSortModelChange
so they work. Both make sense, we just have to decide.We lack good docs examples for the control state (except for the pagination).
I would be in favor of using the
initialState
in the docs examples except for the controlled one to have a clear distinction between controlled and not controlled.Breaking change
If you only want to set the initial value of a state (enable for
preferencePanel
,filter.filterModel
andsort.sortModel
)If you want to fully control the state, use the
filterModel / onFilterModelChange
,sortModel / onSortModelChange
,page / onPageChange
,pageSize / onPageSizeChange
props.