quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Examples: Table with Selection using body-slots

Open marco-quintella opened this issue 6 years ago • 9 comments

Currently, I`m working on a project and I need a table that needs Multiple Selection and use of the BodySlots at the same time.

I tried different approaches but I end with this image

Then its my question and request for an example on the docs of table with selection and using body-slots, since I didnt found a way to fill the first column with checkbox in the right way. Maybe it`s a doubt of others and can be an improvement in the docs.

My Thanks to Quasar Team!

marco-quintella avatar Mar 24 '20 19:03 marco-quintella

I had the same problem a while ago, but don't fear, the props in the body slot provide you a way to select the row!

On your v-slot:body do this:

<template v-slot:body="props">
<q-tr :props="props" @click="props.selected = true">
        <q-td>
          <q-checkbox v-model="props.selected" color="primary" />
        </q-td>
        <q-td v-for="col in props.cols" :key="col.name" :props="props">{{
          col.value
        }}</q-td>
      </q-tr>
</template>

What I did there is to enable the selection by either clicking on the entire QRow OR the QCheckbox, the props.selected property iis a boolean that indicates whether the row is selected or not. as you can see, you can bind it to a checkbox since they output booleans. It's stated in the QTable API documentation for the body slot, although there's no examples for it.

Cheers, Daniel.

danielalejandromatheus avatar Mar 24 '20 22:03 danielalejandromatheus

Thank you @hitostacha for providing the answer. I'd like to see that from more in the community, because this allows us to focus on more features.

rstoenescu avatar Mar 25 '20 10:03 rstoenescu

Thank you guys

marco-quintella avatar Mar 25 '20 23:03 marco-quintella

Thank you. It bothered me for a long time

yeyeck avatar Sep 23 '20 11:09 yeyeck

Thank you. It saved my time.

ignaion avatar Jun 10 '21 03:06 ignaion

Gracias, Necesitaba este tip.

IXColombia avatar Jul 30 '21 22:07 IXColombia

What version of Quasar are you using? As of the time I wrote this, it was 1.5.3, using Vue 2

El jue, 12 ago 2021 a las 11:40, August Vorsterman van Oijen (< @.***>) escribió:

@hitostacha https://github.com/hitostacha

I need this too and tried your example. Here is my code.

Table:

<q-table
  dense
  :title="title"
  :rows="rows"
  :columns="columns"
  row-key="id"
  :pagination="pagination"
  separator="cell"
  selection="multiple"
  v-model:selected="selected"
>

Body slot:

When I click on a row or checkbox I see these errors in the dev console:

Attempting to mutate prop "selected". Props are readonly.

runtime-core.esm-bundler.js?9e79:218 Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'selected' at onUpdate:selected._cache.._cache.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/quasarframework/quasar/issues/6675#issuecomment-897744767, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRGX4ZUK35ME6CWKUMCSODT4PTQNANCNFSM4LS6GAOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

danielalejandromatheus avatar Aug 12 '21 16:08 danielalejandromatheus

What version of Quasar are you using? As of the time I wrote this, it was 1.5.3, using Vue 2 El jue, 12 ago 2021 a las 11:40, August Vorsterman van Oijen (< @.***>) escribió: … @hitostacha https://github.com/hitostacha I need this too and tried your example. Here is my code. Table: Body slot: When I click on a row or checkbox I see these errors in the dev console: Attempting to mutate prop "selected". Props are readonly. runtime-core.esm-bundler.js?9e79:218 Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'selected' at onUpdate:selected._cache.._cache. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#6675 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRGX4ZUK35ME6CWKUMCSODT4PTQNANCNFSM4LS6GAOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Sorry, It was my fault. I deleted my post. It is working as intended, I made a mistake with declaring the selected: [] property.

gvorster avatar Aug 12 '21 16:08 gvorster

Not a problem, glad it's still working. :)

El jue, 12 ago 2021 a las 12:17, August Vorsterman van Oijen (< @.***>) escribió:

What version of Quasar are you using? As of the time I wrote this, it was 1.5.3, using Vue 2 El jue, 12 ago 2021 a las 11:40, August Vorsterman van Oijen (< @.***>) escribió: … <#m_-1285390365326184914_> @hitostacha https://github.com/hitostacha https://github.com/hitostacha I need this too and tried your example. Here is my code. Table: Body slot: <q-tr :props="props" @click https://github.com/click="props.selected = true"> When I click on a row or checkbox I see these errors in the dev console: Attempting to mutate prop "selected". Props are readonly. runtime-core.esm-bundler.js?9e79:218 Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'selected' at onUpdate:selected._cache.._cache. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#6675 (comment) https://github.com/quasarframework/quasar/issues/6675#issuecomment-897744767>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRGX4ZUK35ME6CWKUMCSODT4PTQNANCNFSM4LS6GAOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Sorry, It was my fault. I deleted my post. It is working as intended, I made a mistake with declaring the selected: [] property.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/quasarframework/quasar/issues/6675#issuecomment-897772033, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRGX44UCDKFQHVJROISQYLT4PXX3ANCNFSM4LS6GAOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

danielalejandromatheus avatar Aug 12 '21 20:08 danielalejandromatheus