-
Notifications
You must be signed in to change notification settings - Fork 0
Show total loaded and total filtered items in ItemTable #152
Comments
Working on this. |
Using the const newValue = arr.reduce(function(previousValue, currentValue, index, array) {
// Do stuff with previousValue and currentValue (index, array, and initialValue are optional)
}, initialValue);
In our use case, the only props that we need are |
We are able to access the filtered values from The problem with using this as the only means of calculating the number of items being filtered is that when there is no value in any of the filters the When a column is not filtered in My next steps are to make sure this theory works and find a good way to expose this in the UI. |
Desired text out: "Showing X of Y items" where X is the number of visible (filtered) items and Y is the total number of items. Give a proof of concept that this logic works by addinga typography above the table for now. We'll plan for the UI later. |
This theory worked as expected. Here is a screenshot showing the results before and after filtering. Next StepsThe next step for this issue are finding the best way to expose this in the UI. |
In order to get the number of filtered items, which is accessed from the This state variable should be defined in the In order to se the value of this state variable a new prop needs to be created for the |
To implement this feature I followed the plan that I laid out in the previous comment. This will be a summary of how this implementation works. Create a state variable for filtered itemsIn order to access the number of filtered items from the
+ const [filteredItems, setFilteredItems] = useState(0)
//some code
- <ItemTable data={items} rowCanBeSelected={sidebarOpen} loading={isLoading} />
+ <ItemTable data={items} rowCanBeSelected={sidebarOpen} setFilteredItems={setFilteredItems} loading={isLoading} />
- export default function ItemTable({ data, rowCanBeSelected, loading })
+ export default function ItemTable({ data, rowCanBeSelected, loading, setFilteredItems }) {
//some code
+ useEffect(() => {
+ setFilteredItems(tableInstance.filteredRows.length)
+ }, [tableInstance.filteredRows.length])
Create a component to show informationNext, I created a component, import { makeStyles, Typography, useTheme } from '@material-ui/core'
import React from 'react'
export default function ItemCounter({ filteredItems, totalItems }) {
const theme = useTheme();
const useStyles = makeStyles({
margin: {
margin: '0 1rem'
}
});
const classes = useStyles();
return (
<Typography classes={{ root: classes.margin }}>{`Showing ${filteredItems} out of ${totalItems}`}</Typography>
)
}
ItemCounter.propTypes = {
/** The number of filtered items in the table. */
"filteredItems": PropTypes.number.isRequired,
/** The total number of items in the table */
"totalitems": PropTypes.number.isRequired
};
ItemCounter.defaultProps = {
"filteredItems": 0,
"totalItems": 0,
}; Implement UITo implement this component into the UI we decided that it be best next to the Code //some code
+ "container": {
+ display: "flex",
+ flexWrap: "wrap",
+ alignItems: "center"
+ },
+ queueSelectorContainer: {
+ flexGrow: 2
+ },
//some code
<Box className={classes.leftCol}>
<ItemTableAppBar title="webqueue2" setDarkMode={setDarkMode} />
+ <Box className={classes.container}>
+ <Box className={classes.queueSelectorContainer}>
<QueueSelector
open={queueSelectorOpen}
setOpen={setQueueSelectorOpen}
value={selectedQueues}
setValue={setSelectedQueues}
/>
+ </Box>
+ <ItemCounter filteredItems={filteredItems} totalItems={items.length} />
+ </Box>
<ItemTable data={items} rowCanBeSelected={sidebarOpen} setFilteredItems={setFilteredItems} loading={isLoading} />
</Box>
|
The current implementation of this works well but could benefit from some architectural changes: Instead of prop drilling from AppView to ItemTable, it may be better to consolidate this component to the ItemTable itself. This could be acheived by adding a row to the end of the table that spans all columns and displays the same message of "Showing {number of filtered items} of {number of all items}". Furthermore, this display can be made toggleable via a prop called This also removes the need to modify the containing element of QueueSelector and works well on mobile. |
After some experimentation, the previously mentioned method will not work easily because of react-window's absolute positioning for virtualizing the table. We've hardcoded a This will not be fixed by the current team. This needs to be addressed after a better styling solution for a virtualized table is found. |
Add a UI element to indicate how many items are currently loaded and how many items are filtered if items are being filtered.
The text was updated successfully, but these errors were encountered: