Select row in q-table with button using Vue.js

335 Views Asked by At

When I press the edit button from the action buttons in the q-table, the button opens a modal. However, because the checkbox is not selectable in the q-table, I get an error when I want to update the modal. What I want is for the table to detect that I have selected that row when I click the action button.

My table:

<template>
    <q-table
        title="Students"
        :filter="filter"
        :rows="studentsData"
        :columns="columns"
        row-key="id"
        dense
        selection="single"
        class="puffy-shadow rounded q-pa-lg students-table"
        v-model:selected="selectedStudentRow"
    >
      <template v-slot:body-cell-actions="props">
        <q-td :props="props">
          <q-btn class="action-btn" color="green" icon="mdi-pen" @click="openStudentDialog = true;">
        </q-td>
      </template>
    </q-table>
    <q-dialog v-model="addStudentNoteDialog" class="add-student-note-dialog">
      <q-card>
        <q-card-section>
          <q-form>
            <q-input v-model="note" label="Note" outlined></q-input>
            <q-card-actions align="right">
              <q-btn label="Cancel" color="primary"
                     @click="cancelNote">
              </q-btn>
              <q-btn label="Add Note" color="primary"
                     @click="addStudentNote(selectedStudentRow)">
              </q-btn>
            </q-card-actions>
          </q-form>
        </q-card-section>
      </q-card>
    </q-dialog>
  </template>

<script>
export default {
  name: "StudentsTable",
  data(){
    return{
      openStudentDialog: false,
    }
  }
  computed: {
    selectedStudentRow: {
      get() {
        return this.$store.getters.selectedStudentRow;
      },
      set(val) {
        this.$store.commit('selectedStudentRow', val);
      }
    }
  },
</script>

When the button I want is clicked, the modal opens with the checkbox selected in the table. What I want I showing in this image

I tried with send prop.row in button click event. But it not working.

1

There are 1 best solutions below

0
Shoooryuken On
<q-input v-model="note" label="Note" outlined></q-input>

where is you "note" data ?

If I understood correctly, I would have created something like that:


<template>
    <q-table
        title="Students"
        :filter="filter"
        :rows="studentsData"
        :columns="columns"
        row-key="id"
        dense
        selection="single"
        class="puffy-shadow rounded q-pa-lg students-table"
        v-model:selected="selectedStudentRow"
    >

<template v-slot:body-cell-actions="props">
        <q-td :props="props">
          <q-btn class="action-btn" color="green" icon="mdi-pen" @click="openStudentDialog(props.row)">
        </q-td>
      </template>
</q-table>

<q-card>
        <q-card-section>
          <q-form>
            <q-input v-model="selectedStudent.note" label="Note" outlined></q-input>

        </q-card-section>

</q-card>


[......]
data(){
    return{
      studentDialog: false,
      selectedStudent: {}
    }
  }, 

methods: {
openStudentDialog(student){
    selectedStudent = student
    studentDialog = true
}

something like that