Choose a specific row in a q-table by clicking a button in Vue.js

Whenever I click the edit button located in the action buttons within the q-table, a modal window pops up. However, I encounter an error when attempting to update the modal because the checkbox within the q-table is not selectable. What I am aiming for is for the table to automatically detect the selected row when the action button is clicked.

Below is my table structure:

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

Upon clicking the desired button, the modal should open with the checkbox pre-selected within the table. You can view the desired behavior in this image

I attempted using the send prop.row in the button click event, but it did not work as expected.

Answer №1

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

where do you store the "note" data ?

If my understanding is correct, I would have implemented something similar to this:


<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 in this manner

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

tips for utilizing namespaced getter filtering within a Vuex module in vueJs

In my custom module named ShopItemCategory, I have a Getter getters: { shopItemsCategories: state => state.ShopItemsCategories.data, }, Inside the component, there is a computed function I defined computed: { shopItemsCategories ...

Finding a specific document in MongoDB using a unique slug within Next.js: A step-by-step guide

I have a collection of data in MongoDB structured like this: [ { "Post": "this is a post", "_id": ObjectId("630f3c32c1a580642a9ff4a0"), "slug": "this-is-a-title", "title" ...

AngularJS: intercepting custom 404 errors - handling responses containing URLs

Within my application, I have implemented an interceptor to handle any HTTP response errors. Here is a snippet of how it looks: var response = function(response) { if(response.config.url.indexOf('?page=') > -1) { skipException = true; ...

Encountering a rollbackFailedOptional error during the NPM Install process

When attempting to use various command prompts like Windows Powershell, command prompt as an admin, and bash CMD, I encountered the same error message after trying to run npm install: npm install npm@latest -g The specific error message was: [...] / ro ...

Python Selenium searching for element within iframe has resulted in failure due to the inability to identify the target element

Struggling to find and click a button within an iframe using selenium in Python Currently exploring ways to click a button inside a canvas.renderview, but there seems to be no clear element that corresponds to the desired button. Each time I inspect the e ...

Employing a string key to serve as the v-model in a v-item-group

Is it possible to use a string key as v-model on v-item-group? In the data area, I have the following: payment: null, payments: [ { icon: 'mdi-alpha-p-circle-outline', type: 'paypal', }, { ...

Is it unnecessary to mention both JavaScript and AJAX together?

During a recent conversation I had, someone mentioned that it is inaccurate to state that since Ajax is JavaScript. The scenario was: "How can I perform an action on a webpage without requiring a page refresh?" My response: "Utilize JavaScript along wi ...

`Finding it difficult to halt the spread of events in reactJs`

One of my conditions involves a simple dropdown menu: handleDropdown = (e) => { if (e.type === "focus") { console.log("inside dropdown focus"); this.setState({ dropDownDis: "block" }) } else if (e.type === "blur") { console.lo ...

Unable to transfer the variable name between different node modules for the purpose of using it as a chat room identifier in a socket.io application

Users are able to provide a room name, however when using module.exports in a separate file to retrieve it, the value shows as undefined. This issue likely arises from the asynchronous nature of the process. //roomcheck.js var nsp = io.of("/gameroom"); n ...

Notify the chat when a new record is added to the database

Alright, so here's the issue I'm facing. I created a chat application using PHP and MySQL, but I noticed that when I enter text, it doesn't update in the other window automatically. This led me to experiment with iframes, which I found much ...

Issue with clearing input field after submitting form (React)

I'm struggling to get the input field to clear automatically after clicking the submit button in my React component. I've tried making it fully controlled by React, where the input value depends solely on the state, but I can't seem to figur ...

Utilizing Selenium JavaScript to insert a cookie into a request

Trying to add a cookie to the request in Selenium using JavaScript. I followed the documentation at this link, but my code snippet doesn't seem to pass any cookies to the PHP script below on the server. Here is the client-side JavaScript code: var w ...

Retrieve and process information retrieved from an Ajax call in ASP.NET using AJAX

When I receive a list of data from an Ajax call, it looks like this. $(document).ready(function () { var hashtag = 'dilwale' var accessToken = '16741082.1b07669.121a338d0cbe4ff6a5e04543158a4f82' $.ajax({ url: ' ...

Vue.js lacks the ability to utilize v-model

I'm encountering an issue while trying to send <p class="valikud" v-model="post.store"> {{body}} </p> to my MongoDB database. Unfortunately, it seems that <p></p> is not compatible with v-model. Any recommendations on how I can ...

What is the process for attaching the stack when initializing and throwing errors separately in JavaScript?

In all the documentation I've read, it consistently advises to both throw and initialize errors on the same line. For example: throw new Error("My error"); But what if you were to first initialize the error and then throw it on separate lines? For ...

Creating a global variable for both development and production APIs in Vue 3 is a key aspect in ensuring consistency

Creating a global variable that works for both production and development environments has been challenging. Despite efforts, the variable value remains undefined. I have set up .env and .env.prod files in the project's main directory. VUE_APP_ROOT_ ...

Express.js Failing to Send Response Following POST Request

This is the function I have on the back end using express: // Function to register a new user exports.register_user = function(req, res) { var portalID = req.body.portalID; var companyName = req.body.companyName; var password = req.body.passwo ...

Updating the background color of several tags with jQuery

<rect class="day" fill="#fbedf0" data-count="0"></rect> <rect class="day" fill="#cqe45b" data-count="0"></rect> I am attempting to modify the fill color values of multiple rect tags using jQuery. While I can successfully loop thro ...

Tips for toggling an Electron.js submenu within a Vue.js Component based on a particular Vuex state

I've searched everywhere for a solution to this issue. Currently, I am working on a sample vue-vuex-electron app that I have developed. My goal is to dynamically enable or disable certain submenus within the app based on the vuex state 'isLogged ...

connect the validation of forms to different components

I am currently working on components to facilitate the user addition process. Below is an example of my form component: createForm(): void { this.courseAddForm = this.formBuilder.group({ name: ['', [ Validators.required, ...