Trigger a Tabulator event when a checkbox is selected in Vue 3

Currently, I am utilizing Vue3 along with Tabulator (5.2.7) to create a data table using the Composition API.

In the following code snippets, I have excluded irrelevant parts of the code.

//DataTable.vue
<script setup>
import { TabulatorFull as Tabulator } from 'tabulator-tables';
import { useDataStore } from '@/stores/DataStore.vue';
import { ref, reactive, onMounted } from 'vue';

const store = useDataStore(); //obtaining data from state manager

//following tabulator docs w/vue structure
const table = ref(null);
const tabulator = ref(null);
const tableData = reactive(store.getData);

onMounted(() => {
  tabulator.value = new Tabulator(table.value, {
    layout: "fitDataTable",
    data: tableData,
    reactiveLayout: true,
    responsiveLayout: true,
    selectable: 1, //only allow selection of one row at a time
    columns: [
      {formatter: "rowSelection", titleFormatter: "rowSelection", headerSort: false, cellClick: function(e, cell) {
        const r = cell.getRow();
        console.log(r._row.data);
      }
      //additional data omitted for brevity
    ]
  })
});

//added based on comment reply
tabulator.value.on('rowClick', function(e, row) {
  console.log('hello world')
})

//attempt that did not work, but still tried
// tabulator.on('rowClick', function(e, row) {
//   console.log('hello world')
// })
</script>


<template>
  <div ref="table"></div>
</template>

I regretfully cannot provide screenshots, however, here is an image: https://i.stack.imgur.com/lfeGZ.png

The desired outcome is when the checkbox in the red area is checked, it should log the data and execute other actions. Clicking on the green area should also achieve the same result in addition to selecting the row. Unfortunately, clicking the checkbox does not trigger any functions or console logs. The row gets selected, but no further action occurs.

I have attempted to implement documented event listeners and callbacks from , but each time I try table.on() like

table.on("rowDblClick", () => {return 1})
, an error is thrown claiming that table.on is not a function, and row event listeners were removed in version 5.0.

The main reason behind opting for Tabulator is due to Vuetify's lack of compatibility with Vue3, which is currently in beta phase if memory serves me right. After some searching, I stumbled upon this during my online research.

EDIT: Additionally, if anyone has insights on how to make the built-in event listeners or rowClick callback parameters function correctly, that would be an acceptable resolution.

Answer №1

Managed to successfully implement this by utilizing the rowClick function and relocating the event listener for tabulator within the onMounted section. Additionally, I made adjustments in the ts file by updating the ref type of tabulator to match the import type of tabulator_full:

const tabulator = ref(Tabulator)

onMounted(() => {
  tabulator.value = new Tabulator(table.value, {
    layout: "fitDataTable",
    data: tableData,
    columns: ...
})
    tabulator.value.on("rowClick", function(e, row){
    //perform specific actions
    }
});

Answer №2

If you implement the row selection formatter, you can monitor the rowSelected and rowDeselected events to receive the row component for the chosen/deselected row:

table.on("rowSelected", function(row){
    //row - row component for the selected row
});

To learn more about selection events, refer to the documentation here:

To better understand how to utilize row components, visit the following link:

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

React, facing the challenge of preserving stored data in localStorage while accounting for the impact of useEffect upon

Seeking some assistance with the useEffect() hook in my Taking Notes App. I've set up two separate useEffects to ensure data persistence: one for when the page first loads or refreshes, and another for when a new note is added. I've added some l ...

I want the name of the hospital to be displayed in the dropdown menu with a shortened version of the hospital's name appearing

Check out my code snippet: here import Autocomplete from "@mui/material/Autocomplete"; import TextField from "@mui/material/TextField"; import React, { useState } from "react"; const hospitalList = { docs: [ { _id: ...

Adding functions to the prototype of a function in JavaScript

Is there a more concise way to simplify this code snippet? var controller = function(){ /*--- constructor ---*/ }; controller.prototype.function1 = function(){ //Prototype method1 } controller.prototype.function2 = function(){ //Prototyp ...

JavaScript animation for sequencing traffic lights

I have been working on completing a task that was assigned to me. (iii) Explain the organization of an array that could manage the traffic light sequence. (iv) Develop a script that utilizes the array outlined in part (iii) to create an animated display ...

Is there a way for me to duplicate a complex element multiple times within the same page?

As an illustration, let's say I have a social tab located in my header that I would like to duplicate in the footer. This tab is comprised of various buttons with SVG images on top, event listeners linked to button IDs, and CSS styling. One option is ...

The continuation of unraveling the mystery of utilizing `overflow-y:scroll` in a horizontal slider

As a beginner, I realized too late that adding code in comments is not an option. Consequently, I decided to create a new question and ask for your assistance once again. To optimize the use of space, I have implemented bxSlider with fixed dimensions (wid ...

Add empty objects to an array using a push function following the Vue JS constructor function

During my learning journey with Vue JS, I encountered an issue while attempting to populate an array with objects using a constructor function and the push method. Surprisingly, in Vue JS, the push function inserts a blank object into the array instead of ...

Cannot access a Typescript method variable within an inline function

I've encountered an issue with my code involving loading values into the array usageCategory within an inline function. Despite successfully adding values to the array inside the function, I am unable to print them outside it. getAllUsageCategoryElem ...

Vue.js - the lightweight JavaScript framework without any dependencies mentioned

I'm currently developing a project using Django (Python-based Web Framework) with Vue.js as the front-end framework. Most of the resources I've come across regarding Vue.js mention Node, especially for setting up the development server. I'm ...

What is the correct way to execute the query "select * from table where indexA >= 'a' order by indexB ASC limit 10" in indexedDB?

As I delve into learning about javascript IndexedDB, I have encountered a challenge in executing complex queries. My goal is to perform a select query like this one: "select * from table where indexA >= 'a' order by indexB ASC limit 10" I a ...

How can you utilize both defineProps with TypeScript and set default values in Vue 3 setup? (Typescript)

Is there a way to use TypeScript types and default values in the "defineProps" function? I'm having difficulty getting it to work. Code snippet: const props = defineProps<{ type?: string color?: 'color-primary' | 'color-danger&a ...

Instructions on deactivating the background when the sidebar is displayed and closing the sidebar by clicking anywhere other than the sidebar

I'm in the process of creating a sidebar for my website. When the sidebar is displayed (by clicking showRight), I want to disable the background content so that the user can't interact with anything outside of the menu. If the user clicks on th ...

Create a PDF document with pdfkit and stream it to the browser in a Node.js Express application

I am currently using pdfkit to create a PDF file and I would like to send this PDF directly to the browser. However, I am encountering an error message stating "TypeError: listener must be a function", Additionally, the file is being generated in m ...

Is there a way to verify if an email is already registered within a MERN stack application

I am in the process of creating a registration form and need to verify if an email already exists within the system. Below is the React code snippet showcasing the structure for better understanding. In the schema, emails are defined as unique. AuthContr ...

Combining React, Express, and Nodemailer poses challenges in rendering components and sending emails simultaneously

Looking to utilize client-side routing for my React app and also incorporate Nodemailer for sending emails. However, since Nodemailer cannot be used on the client-side, I need to implement it on the Express server. Here is how the server code looks like: ...

Guide on populating a series of rectangles in a line based on values stored in an array using d3.js

I have 100 rectangles arranged in a 10x10 square. My goal is to assign colors to the rectangles based on values from an array var avg = [1, 4, 4, 7, 11, 15, 58] I'm facing an issue at the value 4 being repeated and I find the current code quite mess ...

Switch up image transitions using Javascript

I have already completed the css and html structure for my project. However, I am encountering issues with the JavaScript functionality. I really like the image effect on this website: (the blue one). I have attempted to replicate it here: , but have bee ...

Regex produces odd results in string processing

This particular JavaScript regular expression: homework.description = (homework.input.match(/((\(((\S\s?)\)?)*)|(about( \w*)*))/i)); When applied to the text: potato (potato) Produces this unexpected output: (potato),(potato), ...

Generating a file using buffer information in node.js

From the front-end client side, I am sending a file to the server. On the server-side, the data received looks something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 6 ...

Creating a table in VueJs and populating it with values retrieved from an MSSQL database in a .NET Core web application

I am developing a table within a .NET Core Web Application that includes multiple rows and columns filled with data retrieved from a MSSQL server through a WEB API Given the need for numerous rows and columns, I am considering using a for loop inside my & ...