-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] multiple data sets state management & filtering #13413
Comments
@davesagraf WOW 🤩 First of all .. it looks like you are filtering manually, is that right? I'll try out some things. |
@michelengelen Hi! Thanks for the reply! Okay, I'll try to make a live code example. Looking forward to your suggestions. Thank you! |
Hey @davesagraf would this be something that potentially solves your usecase? |
Hi again @michelengelen ! Thank you so much for the demo! Yeah, it's very close to what I've been trying to achieve. Just one more thing though, I need to handle and calculate data counters for different states of data based on the status filter as well (and those need to work simultaneously somehow) I've taken your demo and tried to add some logic from my initial code here: new demo But I get this error: |
Hey @davesagraf ... that demo is not public unfortunately |
Hey again @michelengelen , thanks for pointing that out, the demo should be public now |
I think knowing the count before applying the filter is currently not possible, but you could do it manually by counting a filtered array: const array = [
{ status: 'OPEN' },
{ status: 'CLOSED' },
{ status: 'OPEN' },
{ status: 'CLOSED' },
{ status: 'OPEN' },
];
const count = array.filter(item => item.status === 'OPEN').length; but for large data sets this would mean a heavy performance implication. |
Is your usecase to show the expected amount on the button or do you want to show it when actively using the filter? |
@michelengelen Thanks a lot for the tip! Yes, basically, on the high level it would look something like this: There are 5 tabs, on each of which the initial data set is limited to only those rows where data item has the corresponding status. So, for any given tab, we can see, for example, how many of the items with the corresponding status have been left (rows visible) after applying a quickfilter or multifilters. However, if we speak about counters and filter buttons showing them, I was trying to show the actual numbers of all the data filtered by status subsets with the filters currently applied. So, for instance, we have the initial data of 10 items — 10 would be on the 'all' tab (filter button), 5 with a status of 'new', 3 'open', 1 'filled' and 1 'rejected'. So those buttons would already show these initial numbers. Then, if we apply a search or a multifilter value of say 'gmail' for the 'email' field, and 3 of 5 items with the 'new' status, 2 of 'open' and 1 'filled' have them, we should now have filter buttons with these values: And my initial problem was that I was trying to achieve this behavior to be the same no matter on which tab we were when the filter was applied, but in my implementation that worked only on the first tab ('all' in our case), because it had the initial data. |
Hey @davesagraf ... Just a follow up on this: I discussed this briefly with @cherniavskii and he came up with a quick PR (#13418) to resolve this issue. With this it should be possible to achieve what you are trying to implement easily! I will see the PR through, so that you can start using it with the next release (by the end of the week). |
Thank you so much, guys! |
Hi @michelengelen ! I know you and @cherniavskii and other MUI X team members are working hard on a new feature for There's just something I wanted to show you while you're still working on that feature (maybe I'm too early for that, or just didn't get something, if so, sorry for that). Here's a demo which is really close to what I've been aiming for from the very start, but it still has the same problem I've had which got me to open this issue. So, when we're on the 'All' tab (the initial state), we see all the counts and if we apply any other filter in the multifilters, we see the correct updates for all the tabs/status buttons. But, if we click on any of the rest of status buttons ('Open', 'Filled', 'Partially Filled' and 'Rejected'), all other tabs counts inherit the state of that active button we've just clicked. So (again, sorry, if I'm too early for this) my question is — is there a way to make it something like this: So, when we click on the filter buttons ('All', 'Filled', 'Open', 'Partially Filled' and 'Rejected') we only update the visible rows. My goal is to update counts for all the tabs simultaneously, regardless of what 'tab' is active (which status button has been clicked) when we apply any other filter, meanwhile, correctly updating visual rows when we click any of those status buttons. Thanks again! |
@davesagraf this is exactly what you can do when the PR is merged! 👍🏼 |
@davesagraf Ah, I see what you mean. |
@davesagraf I've forked your demo with the latest Data Grid build from the PR: https://codesandbox.io/p/sandbox/pedantic-jasper-frf2zh
It is up to you how you combine the filters. |
Hey @michelengelen ! That's great, thanks a lot! |
Hey @cherniavskii ! Yes! That is exactly what I've been trying to achieve for the past week, but with the previous Data Grid logic "under the hood", that didn't seem possible. Thank you so much! Really looking forward to these updates! |
@davesagraf: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
The problem in depth
Hi everyone!
I would like to share some struggles I've been having with MUI X Data Grid Pro recently and, hopefully, someone much more experienced than I could point me in the right direction or, unfortunately, just confirm my not so optimistic suspicions about the current capabilities of the Data Grid.
So, I have a functionality which is something like this:
A user logs into their account and sees a dashboard which has 5 Data Grid components below (only 1 shown at a time).
Each of those components opens in a separate tab (my app is a SPA, so they are toggled via ToggleGroup, also by MUI).
Those tabs show different Data Grid components which are based on
assetType
(which are 'webService', 'domain', 'ssl', 'ip' and 'port'), but anyway, essentially, we have just 5 different components (each using Data Grid), shown separately (one at a time).Each table also has 5 tabs of their own, 4 of which are based on the asset status filter.
Initial data is without a status filter and is shown on the
all
tab. The rest are corresponding to statusesnew
,inProgress
,fixed
andaccepted
.The most interesting part comes in inside of each of those components, however.
This is an example of my custom
SslTable
:And this is
domain.ui.handleStateChange
function logic which is called inside thedebouncedHandleStateChange
function:This is a custom
ToggleGroup
component which I'm using to display each of the filtered data tabs with corresponding counters:And this is the
filterByStatusHandler
function which I'm calling while toggling between tabs:Now, I have a problem — while I'm on the
all
tab (whiledomain.ui[`${assetType}TableView`]?.entity.filter === 'all'
),everything is working fine: each tab data is correctly filtered, counters are correctly counted and when I toggle between tabs (only if I start from 'all' tab), data and counters remain correct.
But if I apply any search or filter in the Data Grid component while on any other tab ('new', 'inProgress', 'fixed' or 'accepted'),
all tabs data arrays are incorrectly filtered and counters are incorrectly counted (including also breaking filters and counter for 'all' tab data).
I've tried to separately filter data and toggle view for different statuses, but, eventually, either the counters are wrong while updated simultaneously (on any tab other than on 'all'), or, the counters are fine, but only when I pass unfiltered data into the
rows
prop of the Data Grid (but in that case, the views are wrong, since they are not filtered by status).I've tried this to fix the latter like this:
So, basically, I just tried to update the rows of the Data Grid for each of the tab manually without affecting the data passed into the
rows
prop of the Data Grid,which, in turn, affects calculating the counters.
And for that, also, I've tried saving the state from the
api.current.state
while I have unfiltered data on theall
tab, and count filters for other tabs based on that saved state, and not theapiRef
changed in the future, but that also didn't work:So, my guess is — either what I'm trying to achieve is not achievable based on how MUI X Data Grid Pro works right now,
or, if I'm wrong and/or maybe am close to a working solution — I would very much appreciate any help and advice.
Thanks!
p.s.
I'm already using MobX for states in my logic domain stores (all those
this.ui.tableView.entity
andthis[`${assetType}TableView`]?.setEntity({ ...entity, filter: newValue })
lines with states and methods).But I also have been thinking of trying to use
React Context API
for this case, just couldn't wrap my head around of how to do that properly in this case and how it would actually help with the Data Grid underlying issue, of when any change in the data passed into therows
prop of the Data Grid component is causing changes of filter counters on all tabs.I also tried
zustand
, but it hasn't changed much with this issue in particular, unfortunately.Your environment
`npx @mui/envinfo`
Search keywords: state management filtering conditional data for rows
Order ID: 89674
The text was updated successfully, but these errors were encountered: