Error: unable to detect click event on table cell

I need help passing a cell value to a function when clicking on the cell. While it's easy to do this with a regular table, I am trying to figure out how to achieve the same result with bootstrap-vue b-table.

Here is the code snippet for the table:

<b-table
    striped
    responsive
    class="mb-0"
    :items="permissionsData"
  >
    <template #cell(module)="data">
      {{ data.value }}
    </template>
    <template
      #cell()="data"
    >
      <b-form-checkbox
        :checked="data.value"
      />
    </template>
  </b-table>

And here is the method in my Vue component:

methods: {
    onPermissionClick(value) {
        console.log("column name, row name and the value")
    }
},

If anyone has any insights or recommendations on how I can achieve this functionality, please share your thoughts!

Answer №1

<b-table
    striped
    responsive
    class="mb-0"
    :items="permissionsData"
  >
    <template #cell(module)="data">
       <div @click="onPermissionClick">
            {{ data.value }}
       </div>
    </template>
  </b-table>

In this code snippet, the data object includes properties for cell, row, and column. Other properties can be viewed by using console.log(data).

methods: {
    onPermissionClick(data) {
       console.log(data.value)   // Cell Value
        console.log(data.item)   // Row Data
        console.log(data.field) // Column Name
    }
},

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

Vue and TypeScript: The elusive 'exports' remains unidentified

Since switching my App.vue to utilize typescript, I am facing a compiler error: [tsl] ERROR in \src\main.ts(2,23) TS2304: Unable to locate the name 'exports'. If I have vue-serve recompile after making changes, I encounter t ...

Generating and assembling text with vue.js

One of the requirements states that all HTML elements must be defined in a JSON file and utilized within the template. In order to meet this requirement, there is a function called "markComplete" that should be triggered whenever a checkbox is changed. S ...

Showing a Vue component within a Laravel Blade template

Currently, I am performing a basic calculation within app.js by multiplying the product price with the quantity. My goal is to showcase the total value in Laravel for users to preview their order. app.js const app = new Vue({ el: '#item', ...

Sharing information with Vue.js component

Currently, I am in the process of developing a component and need to pass two properties (item & brokerageID) to this particular component. Below is the HTML code snippet that illustrates how these properties are passed: {{brokerageID}} <holiday-compon ...

What could be preventing my component from importing properly in App.vue?

I am attempting to display a pulse loader while the page is loading. However, I encountered two errors in the code below. App.vue <template> <div id="app"> <div id="nav"> <router-link to='/'><div v-if="$ro ...

Set the Vue 3 Select-Option to automatically select the first option as the default choice

I am attempting to set the first select option as the default, so it shows up immediately when the page loads. I initially thought I could use something simple like index === 0 with v-bind:selected since it is a boolean attribute to select the first option ...

I'm having trouble locating a declaration file for the module 'vue-prism-component'

Currently utilizing Vue 3 (Composition API), Vite, and Typescript but encountering a missing module issue with vue-prism-component. <script lang="ts" setup> import 'prismjs' import 'prismjs/themes/prism-tomorrow.css' imp ...

Transition and transition-group animations in Vue.js do not seem to be functioning correctly

Having trouble implementing CSS transitions between slides in a Vue 2 Carousel component. Slides are created using v-for and shown/hidden using v-show. Attempted to use <transition> with mode=out-in, but encountered issues with two slides displaying ...

Sending Component Properties to Objects in Vue using TypeScript

Trying to assign props value as an index in a Vue component object, here is my code snippet: export default defineComponent({ props:{ pollId:{type: String} }, data(){ return{ poll: polls[this.pollId] } } }) Encountering errors wh ...

Analyzing CSS using browser development console with Vue CLI

After following various Vue CLI examples to successfully incorporate SCSS files into my Vue file, I noticed that the page now loads with the imported CSS, but I am unable to determine which file/line number the CSS declaration is coming from. The Chrome co ...

What is the best way to implement a required input field in Vue.js?

I need some assistance with my chat functionality. I want to prevent users from sending empty messages, so I want to make the input field required. Can you please help me with this? I have already tried adding "required='required'" to the input ...

Is it possible that the v-if directive is not functioning properly with the script setup in vue2.7? Have the syntax requirements changed in vue2

<template> <div> <button @click="handleClick">toggle</button> <span v-if="isToggled()"> hidden message </span> </div> </template> <script setup lang="ts" ...

What are your thoughts on utilizing for loops within the same function in Vue to organize fetched data?

Currently, I am implementing a fetch request to retrieve data from an API. The data is then converted to JSON format and I would like to organize it into separate categories. For instance, tickets with the status "active" should be placed in one array whil ...

Executing Nuxt middleware on the client-side post static rendering

We are transitioning from using a Single Page Application to statically generated pages, but we are encountering an issue with middleware. Essentially, when Nuxt is statically rendered, the middleware runs on the build server first and then runs again aft ...

Preventing the insertion of a line break when using Shift + Enter in Vuejs

Whenever I use a textarea to enter text, I find that I have to press Shift + Enter every time to send the text. However, upon sending, it adds /n at the end. I prefer using the Enter key for newline instead of submitting the form. Example: hello => ...

What are the steps to successfully implement createApp in Vue 3 within your application?

Transitioning from Vue 2 to Vue 3, I encountered a challenge. In Vue 2, global component registration was easy as shown in main.js new Vue({ el: '#app' }) To globally register a component in Vue 2, you would do this: my-component.js Vue.compon ...

Problem encountered when attempting to utilize the spread operator within .vue files in an Elixir Phoenix 1.3 application

I'm facing an issue while building Vue.js components that involve using the spread operator to map states from Vuex within my Phoenix 1.3 application. The JavaScript compile errors I encountered are causing some roadblocks: 26 | }, 27 | compu ...

In my programming world, 'i' is a mysterious being - always undefined, except when it decides

Currently, I am utilizing Vue, Vuedraggable, and Vuetify in my project. I have encountered an issue where I am unable to use 'let' to define the index for my loop as it always returns undefined. Strangely, using 'var' instead of ' ...

Failed Deployment on Netlify

My website is currently displaying an "Error establishing a database connection" message. The deploy log indicates that the issue lies within Gridsome. The log below details the deployment process. As a novice, I'm seeking advice on how to troubleshoo ...

Managing the storage of refresh and authorization tokens on the client side: where should they be kept?

My backend is powered by Laravel and the frontend uses Vue. Users authenticate by calling my Laravel API to get an Auth token and a refresh token. The Auth token expires after 2 minutes, while the refresh token lasts longer. Storing the refresh token in l ...