search

Home  >  Q&A  >  body text

Select rows in q-table via buttons using Vue.js

<p>When I press the edit button in the action button in <code>q-table</code> the button opens a modal. However, since the checkbox in <code>q-table</code> is not selectable, I get an error when I want to update the schema. What I want is when I click the action button, the table detects that I have selected the row. </p> <p>My table:</p> <pre class="brush:php;toolbar:false;"><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></pre> <p>When the button I want is clicked, the modal opens and the checkbox is checked in the table.What do I want to show in this image</p> <p>I tried sending prop.row on button click event. But it doesn't work. </p>
P粉384679266P粉384679266475 days ago606

reply all(1)I'll reply

  • P粉349222772

    P粉3492227722023-09-03 15:10:08

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

    Where do you "log" the data?

    If I understand correctly, I would create something like:

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

    Similar things

    reply
    0
  • Cancelreply