Request : Allow user provided search text, shown columns, sorting, etc.
See original GitHub issueFirst, thank you for making this amazing datatable module. As I’m using material-ui for the first time, I couldn’t be happier with such an amazing tool that automatically uses the theme of my application and offers so many features to pick from.
That being said, I love your callback functions that inform us about what the current search query is, which filters are applied, etc. I decided to use those callbacks to implement a “persistent” config in my application, so that the datatable can automatically render using the persistent config if the table is ever unmounted / mounted back in a short period of time.
Expected Behavior
To be able to render the DataTable by providing the searchText, displayedColumns, etc.
This feature would make it easy to “persist” every datatable settings on componentWillUnmount (in cookies, for example) then to load them back the next time the DataTable is mounted.
Current Behavior
Currently, we are able to provide the “filterList” array, which makes us able to save the user filters and load them back anytime we want (great !), but other options (like the search query or the current sorting parameters) cannot seem to be provided as props.
Example of an expected behavior :
constructor(props) {
super(props);
// Retrieve the persisted settings and set them to the state
}
componentWillUnmount() {
// Retrieve the settings from the state and persist them (cookies, local storage, wherever)
}
handleWhateverFunction() {
// Update the current state with the latest changes
}
render() {
const { data } = this.props;
const { filtersConfig, searchQuery, sortingConfig, displayedColumns } = this.state;
return (
<DataTable
columns={config.columns}
data={data}
options={{
displayColumns: displayedColumns,
filter: true,
filterList: filtersConfig,
searchText: searchQuery,
selectableRows: false,
textLabels: config.labels,
print: false,
responsive: 'scroll',
onDisplayedColumnsChange: this.handleDisplayedColumnsChanged,
onFilterChange: this.handleFilterChange,
onRowClick: this.handleRowPress,
onSearchChange: this.handleSearchChange,
onSortChange: this.handleSortChange,
sortingList: sortingConfig
}}
/>
);
}
Your Environment
Tech | Version |
---|---|
Material-UI | 3.4.0 |
MUI-datatables | 2.0.0-beta-38" |
React | 16.4.1 |
browser | Chrome |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
I’m trying to find the time to redo the filterList along side many other options that would be used to rehydrate the table. It’ll be a breaking change in the near future but bear with me
I also need this default searchText option, for After page reloading. On my strategy with Server query,
search
events, savesearchText
on Web Browser URL and fetch data from ServerNext Page
button, Server query does’t includes searchTextYes, I can avoid this problem via comparing State’s (from URL)
searchText
vs MUIDataTable’ssearchText
before Server query. But I hope I can set MUIDataTable’ssearchText
initially.