question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Manage selected state in the data-table component instead of in the data itself

See original GitHub issue

Currently 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:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nekosaurcommented, May 16, 2017

Implemented in #516

0reactions
lock[bot]commented, Apr 17, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found