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

How to disable selection input in <UTable>? #1775

Closed
heydayle opened this issue May 10, 2024 · 6 comments
Closed

How to disable selection input in <UTable>? #1775

heydayle opened this issue May 10, 2024 · 6 comments
Labels
question Further information is requested

Comments

@heydayle
Copy link

Description

Enviroment:

Node version: v18.19.1

Nuxt version: 3.11.2

Nuxt UI version: 2.15.2

<script setup lang="ts">
const columns = [
  {
    key: 'name',
    label: 'Name',
  },
  {
    key: 'actions',
  },
]

const people = [
  {
    id: 1,
    name: 'Lindsay Walton',
  },
  {
    id: 2,
    name: 'Courtney Henry',
  },
]

const selected = ref([])
</script>

<template>
  <UTable v-model="selected" :rows="people" :columns="columns">
    <template #name-data="{ row }">
      <span :class="[selected.find(person => person.id === row.id) && 'text-primary-500 dark:text-primary-400']">{{ row.name }}</span>
    </template>
  </UTable>
</template>

Currently, I'm using selection feature of in NuxtUI, but I don't know how to disable checkbox selection for a rows or all rows.

Screenshot 2024-05-10 at 16 57 23

I learn about on Doc's NuxtUI but I don't see it's mention to this problem.

If anyone has a way to handle it, please share with me.
Thank you very much!

@heydayle heydayle added the question Further information is requested label May 10, 2024
@thien0110
Copy link

I am also facing the same issue.

@madsh93
Copy link

madsh93 commented May 13, 2024

You have to leave out the v-model part.

If you still want to use the functionality of being able to click a row, you can use the @click function.

EDIT: ups misread your question. But you could still do this without v-model and add your own col for a checkbox.

@heydayle
Copy link
Author

You have to leave out the v-model part.

If you still want to use the functionality of being able to click a row, you can use the @click function.

EDIT: ups misread your question. But you could still do this without v-model and add your own col for a checkbox.

Thanks @madsh93, i will try it.

I will update more info about problem in this ticket

@heydayle
Copy link
Author

I've tried customizing a selection column using <UCheckbox> and everything seems to be working fine.

The next step is to add 2 properties, isSelect and disabled to each row.

You can check it out here: https://stackblitz.com/edit/nuxt-starter-bb3fnm?file=app.vue

I'll close this ticket here, thanks.

@gilles6
Copy link

gilles6 commented May 30, 2024

Is possible to disable this selection column and re-enable it from given condition?

@heydayle
Copy link
Author

heydayle commented Jun 5, 2024

Is possible to disable this selection column and re-enable it from given condition?

Yes, we can

You just need to change the input condition in props disabled of <UCheckbox>

<template #select-data="{ row }">
   <UCheckbox
      v-model="row.isSelect"
      :disabled="yourCondition" // change your condition here!
      @change="selectRow(row)"
  />
 </template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants