Attempting to extract the cell information and choose an option from a cell using the Tabulator program

I've been using Tabulator, which is an amazing tool, but I've run into a little trouble. I'm trying to add an HTML Select in each row, with options specific to each record. When I change the select option, I call a function and successfully retrieve the cell data using cell.getData(). However, I'm having difficulty figuring out how to also get the value of the selected option.

Here's what I'm attempting to achieve

Here's a snippet of my code:

var selectHTML = function() {
    return '<select class="custom-select" id="select1" name="select1"><option value="0">Select</option><option value="1">Option 1</option><option value="2">Option 2</option></select>';};

var table = new Tabulator("#example-table", {
langs: {
    "es-es": {
        "pagination": {
            "first":"Primer página",
            "first_title":"Primer página",
            "last":"Última página",
            "last_title":"Última página",
            "prev":"Anterior",
            "prev_title":"Anterior",
            "next":"Siguiente",
            "next_title":"Siguiente",
            "page_size":"Resultados a mostrar"
        },
        "ajax":{
            "loading":"Cargando",
            "error":"Error"
        },
    },
},
height:"500",
layout:"fitColumns",
placeholder:"Sin datos",
responsiveLayout:true,
pagination:"local",
paginationSize:10,
paginationSizeSelector:[3, 6, 8, 10, 50],
movableColumns:true,
columns:[
    {title:"Zipcode", field:"zipcode", sorter:"number"},
    {title:"Productor", field:"nombre", sorter:"string"},
    {title:"Action", formatter:selectHTML, cellClick:function(e, cell){
        var selectedValue = cell.getElement().find("#select1").val();
        test(selectedValue, cell.getData());
    }},
    {title:"", formatter:editIcon, align:"center", cellClick:function(e, cell) {
        var data = cell.getData();
        modifyName(data);
    }},
],
locale:"es-es"

});

function test(selectedOption, data) {
    if(selectedOption != 0) {
        alert("Chosen option: " + selectedOption);
    }
}

Any insights would be greatly appreciated. Thank you!

Answer №1

This is how I managed to solve my issue:

var el = cell.getElement().children.select1.value;
runTest(el, cell.getData());

*runTest is the function's name

However, I encountered a new problem where runTest() gets triggered every time I click on a cell:

{title:"Action", formatter:selectHTML, cellClick:function(e, cell) {
        var el = cell.getElement().children.select1.value;
        runTest(el, cell.getData());
}},

I only want it to run when the select option is changed...

I'm looking forward to any suggestions. Thanks!

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

Is there a way to include two functions within a single ng-click event?

Is it possible to incorporate two functions in a single ng-click event? Below is the code snippet: <button class="cButtonSpeichern" ng-click="saveUser()">Speichern</button> In addition, I would like to include this function as well. alert ...

What might be the reason behind a persistent JSON request for a fresh session?

After deploying a Rails 3.0.3 app, we encountered the following error: Started GET "/session/new" for 74.222.223.113 at Fri Feb 25 16:22:30 -0800 2011 Processing by SessionsController#new as JSON Completed in 25ms ** [Hoptoad] Success: Net::HTTPOK ** ...

Angular Bootstrap notifications will stay open indefinitely and will not automatically dismiss after a certain period

I need help with adding alerts using Angular Bootstrap that should dismiss themselves after a certain timeout. However, the alerts are not dismissing on their own. Here's the code snippet: angular.module('ui.services').service('AlertSe ...

Here's how you can use welding techniques to attach objects and incorporate fin-like structures in THREE

I am currently working on a project involving a rocket ship orbiting various planets. To achieve this, I have started by creating my own rocket ship object and am aiming to model it similarly to this design: https://kyleagnew.files.wordpress.com/2018/02/lo ...

Generate a dynamic key object in Angular/TypeScript

I am working with an object called "config" and an id named "id". My goal is to create an array of objects structured like this: [ "id" : { "config1: ... "config2: ... "config3: ... } "id2" : { "config ...

Transmit JSON information from one webpage and dynamically retrieve it from another page via AJAX while both pages are active

I am attempting to transfer JSON data from page1 when the submit button is clicked and then retrieve this data dynamically from page2 using AJAX in order to display it in the console. I am unsure of the correct syntax to accomplish this task. There was a s ...

Struggling with getting my Vue-CLI app deployed on Heroku

After diligently following all the steps outlined in this tutorial: https://codeburst.io/quick-n-clean-way-to-deploy-vue-webpack-apps-on-heroku-b522d3904bc8 I encountered an error message when checking my app at: The error indicated: Method Not Allowed ...

Dealing with asynchronous requests in Axios: A guide to solving the challenge

I'm working on a page named _id.vue in my Nuxt.js project: <template> <div class="wrapper"> <HeaderApp> <DivHeaderMenu> </DivHeaderMenu> </HeaderApp> <CenterContentDinamicFirmeni ...

Module for React Native that enables users to select and copy text within a specified view

Is there a feature that enables users to highlight and copy text from within a view? If not, is there a method to identify all "Text" type elements and extract the text they contain? <View> <Text>Text1</Text> <Text>Text2</Text& ...

Modifying an element in an array while preserving its original position

Currently, I am working on updating the state based on new information passed through response.payload. Here is my existing code snippet: if(response.events.includes('databases.*.collections.*.documents.*.update')) { setMemos(prevState => pre ...

Is it possible to verify the presence of the "#" tag within a string?

As a novice in node.js, I appreciate your patience with my question. We are aware that we can use var regex = /[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/g; regex.test(str); to verify if a string contains special ...

Sending Node.js FileStream Image to HTML5 FileReader API

Is there a way to utilize Node FileSystem for opening a file and then having it read by the FileReader API? const myFile = "C:\\Users\\Me\\Image.png"; fs.readFile(myFile, (error, data) => { const blob = new B ...

CSS photo display with magnification feature

I currently have a functioning inner-zoomable image set up with the code provided. I am interested in converting this setup into an image gallery with zoom capabilities for the selected image element, but I'm unsure where to start. My objective is to ...

How can I open links inside a .load jquery page without refreshing the page?

I have successfully implemented a jQuery code that updates the search query when I click on a checkbox. However, I am facing an issue with pagination on the loaded page. Whenever I click on the next button or any pagination links, the page refreshes and th ...

Tips for bypassing the 304 not modified error in Rails4 and fixing issues with AJAX functionality

As a novice in the world of Rails, I am currently working on creating a basic application with it. However, I am encountering an issue where every time I refresh or reload a page, it returns a 304 not modified status and ajax functionality ceases to work ...

"Resizing issue with multiple Highcharts not being resolved after selecting a new option from

Is there a way to resize multiple Highcharts on a webpage by clicking a button? When attempting to update the last chart using a dropdown menu and then clicking the resize button, an error message stating Uncaught TypeError: Cannot read property 'refl ...

Displaying the month name in the Ajax calendar extender

I recently added an extender to a text box for selecting dates. However, the date it displays shows the number of the corresponding month rather than the name. Is there a way to customize it so that it shows the month name instead? For example, I currently ...

concealing directory titles within HTML and AJAX

What are the potential security risks associated with exposing PHP folder names? If there are risks, what methods can be used to conceal the folder names within html hyperlinks and ajax code? ...

Replace a portion of text with a RxJS countdown timer

I am currently working on integrating a countdown timer using rxjs in my angular 12 project. Here is what I have in my typescript file: let timeLeft$ = interval(1000).pipe( map(x => this.calcTimeDiff(orderCutOffTime)), shareReplay(1) ); The calcTim ...

Javascript continues to execute even after the designated element has been eliminated or substituted

I'm currently working on a WordPress auction site using WooCommerce that needs a countdown timer to display when a specific product auction is ending. Below is the JavaScript code for the countdown timer: const getElem = elem => document.q ...