Utilize Devextreme's dxDataGrid component to transmit the selected RowData to a function upon clicking a button within that particular row

I am utilizing the dxDataGrid user interface widget from the Devextreme product.

My goal is to transform one of its columns into a clickable button. Here is my progress so far:

Field Configuration

  { dataField: 'LetterNumber', caption: 'Letter Number', cellTemplate: showLetterImageTemplate }

CellTemplate Setup for Button Display

function showLetterImageTemplate (cellElement, cellInfo) {
    cellElement.html(' <button class="btn btn-info btn-sm btn-block" ng-click="show('+cellInfo+')">' + cellInfo.displayValue + ' </button> ');
    $compile(cellElement)($scope);
};

Function Triggered by Button Click

$scope.show = function (cellInfo) {
    DevExpress.ui.notify("TEST" + cellInfo.data, "error", 2000);
}

The issue I am facing is with passing the data of the clicked row to the Show() function to identify the specific row. When I click the button, it throws the following error:

ng-click=Show([Object Object])

For information, I am integrating Angular into my UI framework.

Answer №1

Implement the code below to set the cellTemplate:

$scope.onClick = function(cellInfo) {
    // cellInfo object
};

$scope.dataGridOptions = {
    dataSource: [
        { name: "Alex", age: 23 },
        { name: "Bob", age: 25 }
    ],
    columns: [
        "name", {
        dataField: "age", cellTemplate: function(cellElement, cellInfo) {

            var $button = $("<button>")
                .text("Click me")
                .on("click", $.proxy($scope.onClick, this, cellInfo));

            cellElement.append($button);
            }
        }
    ]
};

Then, insert this HTML code in the view:

<div dx-data-grid="dataGridOptions"></div>

Trust it helps!

Answer №2

// Your code can be modified to include this functionality        
columns: [
    // ...
              {
                dataField: "LetterNumber",  
                caption: "Letter Number",
                cellTemplate: function (container, cellInfo) {
                  var gridButton = $("<button>")
               // (if necessary)
               // .attr("attribute name (i.e. class, disabled)", "attribute value")  
                  .text("Show Letter")
                  .on("click", function () { $scope.show(cellInfo) });

                  container.append(gridButton);

                }

              }
    // ... 
    ]

You may find this example helpful: https://codepen.io/alfredomason1986/pen/KveBNd

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

Using jQuery to include a sub-object in the "data" object for each AJAX request made on the webpage

Is there a way to enhance the functionality of jQuery.ajax by including a static sub-data object in every ajax request automatically? For instance, for an ajax request like this: jQuery.ajax({ url: 'request_file.php', data: { da ...

Angular2 allows you to create pipes that can filter multiple values from JSON data

My program deals with an array of nested json objects that are structured as follows: [{name: {en:'apple',it:'mela'}},{name:{en:'coffee',it:'caffè'}}] I am looking to implement a pipe that can filter out objects b ...

Enhance Your Vue.js 2.0 Experience: Implementing Vue Components Generated with v-html and Compiling the Markup

Currently Utilizing VueJS 2.0 I am looking to transform the following into a clickable link. Is this possible? This is my vue component: <template> <div v-html="markup"></div> </template> <script> new Vue({ data() { ...

Tips for confirming a date format within an Angular application

Recently, I've been diving into the world of Angular Validations to ensure pattern matching and field requirements are met in my projects. Despite finding numerous resources online on how to implement this feature, I've encountered some challenge ...

Issue with integrating the jquery tokeniput plugin in asp.net mvc 3

Having trouble integrating the jQuery Tokeninput plugin into my MVC application. Something seems off with the setup... The Code I'm Using: <input type="text" id="MajorsIds" name="MajorsIds" /> <script type="text/jav ...

Manipulating Images with jQuery: Adding and Removing Images Without Affecting Text

Below is the code I'm working with: <input type = checkbox id = "purple" name = "box" > Purple </input> <div id = birdcage></div> This is the JavaScript section: $("#purple").click(function(){ if ($("#purple").is(":chec ...

Retrieving information within the iteration

I am facing an issue with connecting to an external server named Pexels in order to retrieve photos from node.js. The problem seems to be related to JavaScript, as Pexels limits the user to download up to 40 pictures per page. https://api.pexels.com/v1/cu ...

Leveraging JavaScript variables within a jQuery selector

My <form> includes the following input... Term ID: <input type="text" name="data_array[0][term_id]" size="5" value="' . $highest_term_id . '"> with the $highest_term_id being set by PHP. I am attempting to increment the "data_array ...

Convert epoch time to HHMM format using JavaScript

I have a specific variable that stores epoch time data. My goal is to showcase the time information in HHMM format. Below you can find the code I am currently using; function convertEpochTimeToDateObj(epoch_time) { var utcSeconds = epoch_time; va ...

Error: Material UI search bar doesn't refresh interface

I implemented Material UI's auto complete component to create a dynamic select input that can be searched. The component is fed options in the form of an array consisting of strings representing all possible choices. <Grid item xs = {props.xs} cla ...

Using a nested loop in Javascript to fetch JSON data

My goal is to display Categories and their corresponding subcategories in a specific order. However, my current method of using loops within loops is not producing the desired outcome: Category(Mobile) Category(Laptop) Subcategory(Iphone4) Subcategory(Iph ...

Guide on deleting an element from an object array based on the content of a specific field (resulting in undefined mapping)

I am working on integrating a task list feature using React. I have created a state to store the id and content of each task: this.state = {tasks: [{id: 123, content: 'Walk with dog'}, {id: 2, content: 'Do groceries'}]} Adding elements ...

What is the reason `addEventListener` does not work with a class method?

Recently, I discovered that the listener passed to addEventListener can actually be an object with a handleEvent function instead of just a callback function (here). However, I encountered an issue when trying to use handleEvent as a class method: class F ...

Error in scrolling previews detected in Jssor horizontal template maker

I've been working with Jssor Slider Maker and I'm using the vertical preview template that features two columns on the left side and a maximized image on the right side. After pulling the code from the developers pack, it includes scripts, CSS an ...

Host several Node.js applications concurrently on one server

Attempting to run multiple Node.js apps on a single server has been my focus lately. I have been exploring solutions for similar queries here and have reached some progress. Let's consider the scenario where I have two apps, each serving different HTM ...

The div element nested within the button is not visible

Fiddle I am trying to create a unique social button design that resembles the custom Google+ sign-in button: However, I encountered an issue where the second div element (to hold the right part of the button) is not displaying as expected: Here is the c ...

Combine and calculate the total of several columns using the Loadash library

In my Vue application, I am faced with the challenge of grouping an array by date and then calculating sums for multiple columns. The current method I have only allows me to group and sum one column: receiptsByDate: function(){ let byDate = _.groupBy(t ...

When trying to console log a selected date, the output displays as undefined

<div class='col-sm-6'> <input [(ngModel)]="date" id="date" name="date" class="form-control" required/> </div> $(function () { $('#date').datetimepicker({ format: 'DD/MM/YYYY hh:mm' } ...

A perfect illustration showcasing the distinction in practical applications for the operators `=` and `&`

Although I grasp the technical distinction between using = and & in isolated scopes, such as understanding what is assigned to isolate scope property: // "=" isolateScopeProperty = getter(parentScope) // "&" isolateScopeProperty = function(locals ...

Ways to display a different div when clicking on a div?

Good afternoon, I've noticed that this question has been asked numerous times before, but none of the solutions provided seem to work for my specific issue. My problem involves a div with the class .title3. I want another div with the class .Content ...