Manage selected state in the data-table component instead of in the data itself
See original GitHub issueCurrently the data-table stores its state within the data itself, which I find highly problematic.
Storing view state in data models
Pros Not sure
Cons
- You have to map selected state to every data item.
- That gets complicated if your data is reactive.
- And even more complicated if your data is immutable, e.g. from a data store like Vuex.
- And even more complicated if the same data is used in a table more than once as the selected state is remembered in the store.
- And even more complicated if your server enforces schema or doesn’t sanitize your submitted data
- Lastly, you risk data corruption in case your data entries already have a value property and you’re unaware that the selected state by default overwrites the value.
Many of the cons listed can be tackled through various boilerplate, methods, computed methods, watchers, server sanitation etc., but the crux of the matter is, view state shouldn’t leak into the data in the first place.
The current data-table uses the following scope
props: {
item: {
value: false,
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
sodium: 129,
calcium: '8%',
iron: '1%'
}
}
I propose this
props: {
checked: false,
item: {
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
sodium: 129,
calcium: '8%',
iron: '1%'
}
}
Move the checked state out of the item and into props and keep the logic inside the data table component. The selected state can be be queried through $ref as well as emitted from the data table component.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
react-data-table-component: access the selected row and ...
This is a property of react to batch all state updates made in a synchronous scope altogether and make all the state changes...
Read more >State saving - DataTables example
DataTables saves the state of a table (its paging position, ordering state etc). When the stateSave option is enabled, it can be restored...
Read more >LWC: Datatable - preselect rows programmatically
Load data via init handler first // then handle programmatic selection handleSelect() { const rows = ['a']; this.selectedRows = rows; }
Read more >Building a Data Table Component in React — Development
First, create a basic data table component that receives as props an array of headings and an array of rows. Map over these...
Read more >DataViews - ADO.NET - Microsoft Learn
This behavior differs from the Select method of the DataTable, which returns a DataRow array from a table based on a particular filter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Implemented in #516
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please direct any non-bug questions to our Discord