Skip to content
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

[Feature Request] Add option to only select one row at a time in data tables #2960

Closed
jim0thy opened this issue Jan 8, 2018 · 13 comments
Closed
Assignees
Labels
T: enhancement Functionality that enhances existing features
Milestone

Comments

@jim0thy
Copy link

jim0thy commented Jan 8, 2018

New Functionality

Option to select one row at a time in a data table, radio-button style. Selecting a new row will clear the previous selection.

Improvements

No existing workaround

Bugs or Edge Cases it Helps Avoid

Allows the user to provide extra functionality in custom components based on a guaranteed single-row selection in the data table; a preview pane, for example.

@nekosaur nekosaur added the T: enhancement Functionality that enhances existing features label Jan 12, 2018
@slippyC
Copy link

slippyC commented Jan 12, 2018

Yep, would like this as well. Was fixing to start writing some code, to attempt, to do something similar.

@benjaminpwarren
Copy link

As a workaround, you can just use <v-radio-group> and <v-radio>:

  <template slot="items" slot-scope="props">
    <tr @click="selected = props.item.id">
      <td>
        <v-radio-group
          v-model="selected"
          name="rowSelector">
          <v-radio :value="props.item.id"/>
        </v-radio-group>
      </td>
      <td>...</td>
    </tr>
  </template>

Note: Don't specify v-model on the <v-data-table>.

@FabioZanchi
Copy link

Yes! This feature would be great.

@benjaminpwarren Could you please make a quick example on Codepen or Fiddle about how it works?
I've tried to do it here but It's not working.

Cheers

@nekosaur nekosaur self-assigned this Feb 16, 2018
@benjaminpwarren
Copy link

benjaminpwarren commented Feb 23, 2018

@FabioZanchi, here you go.

(Note that in my snippet in my previous post, I used .id as the "key", whereas in the linked CodePen I've used .name as there was no .id in the source.)

Edit: I've just noticed that the selected radio doesn't 'move' when the table is sorted. There's probably a quick fix and I'll look into when I get a chance.

@FabioZanchi
Copy link

Thanks, @benjaminpwarren!

I'll have a look!!

@uxweb
Copy link

uxweb commented Apr 4, 2018

Hi @benjaminpwarren

Thanks for publishing the example for selecting a row with a radio button. Have you discovered how to fix the fixed selected radio button? When I select a row and skip to the next page, the radio button keeps selected in the new page.

Best regards

@zerosym
Copy link

zerosym commented Aug 11, 2018

In case someone comes across this and needs a fix still for the workaround @benjaminpwarren posted, you can just add a unique :key="" to the v-radio. In the codepen example it'd be :key="props.item.name"

The problem is when you page the data table it attempts to reuse the v-radio components. In Vuetify's checkbox version this doesn't matter since the checkbox values are forced to update to match their corresponding rows' props, whereas in the radio group case the value of the radio is unchanging.

@KaelWD KaelWD modified the milestones: v1.2.0, 2.0 Aug 22, 2018
@nekosaur nekosaur mentioned this issue Oct 6, 2018
9 tasks
@johnleider johnleider modified the milestones: 2.0, v2.0.0 Oct 7, 2018
@andrewackerman
Copy link

As I didn't want my table to be covered in auxiliary radio buttons, my work-around solution to this was to set a data object equal to the item of the clicked row and then check against it during the calculation of the :active property of the rows on the refresh. See here.

@nekosaur nekosaur mentioned this issue Nov 26, 2018
9 tasks
@iKoru
Copy link

iKoru commented Dec 26, 2018

Hey guys, wouldn't it be better if we use this way?

<tr @click="selected = (selected===props.index?null:props.index)">
  <td>
    <v-checkbox :input-value="selected === props.index" primary hide-details></v-checkbox>
  </td>
</tr>

I found it works well.

@RiickNogueira
Copy link

RiickNogueira commented Jan 24, 2019

The best solution for me was to just recode the method @click used in the Vuetify documentation example.

<tr :active="props.selected" @click="select(props.item)">
select(selectedItem) {
      this.selected = [];
      this.items.forEach(item => {
        if (item.id == selectedItem.id) {
          this.selected.push(item);
        }
      })

All remaining code is the same. Complete solution here.

@morgenweck
Copy link

Yes! This feature would be great. Me too!

@ShayanBits
Copy link

Yep, I also need this feature.
Thanks @benjaminpwarren for the workaround and thanks @zerosym for the tip. It works fine with the workaround. 👍

@blalan05 blalan05 closed this as completed Apr 2, 2019
@tnikolai2
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement Functionality that enhances existing features
Projects
None yet
Development

No branches or pull requests