Issue with button click functionality within Angular grid's Celltemplate

Has anyone experienced issues with the click event not working when using celltemplate in AngularJS?

    $scope.format = function(val){
            return val.replace(/\//g, "");
        };

        var executionColumns = {
            data: [],
            enableSorting: true,
            paginationPageSizes: [25, 50, 75],
            paginationPageSize: 25,
            enableColumnMenu: true,
            enableFiltering: true,
            columnDefs: [

              { field: 'StartDate', cellTemplate: '<button ng-click="format (row.entity)">log</button>' },
              { field: 'Status' },

            ]

        };

Seeking advice on how to troubleshoot this issue. What could be causing the problem?

Answer №1

I found that the second block of code is what works best for me.

         columnDefs: [
          { field: 'StartDate', cellTemplate: '<button ng-click="format(grid.getCellVale(row.entity)   )">log</button>' },
          { field: 'Status' },

        ]

If you prefer, you can also move your format function to an external scope like this:

 $scope.globalExternalScope = {
       format:function(entity){..........}
    }

You would then use the template as follows:

         columnDefs: [
          { field: 'StartDate', cellTemplate: '<button ng-click="getExternalScopes().format(grid.getCellVale(row.entity)   )">log</button>' },
          { field: 'Status' },

        ]

Answer №2

Implement

<button ng-click="grid.appScope.format (row.entity)">log</button>

This method is currently operational for me!

Answer №3

If you are utilizing the .component with a nested ui-grid and have defined a method as:


this.handleClick = function(){...}

You can access this method in the cellTemplate like so:


cellTemplate: '<button ng-click="grid.appScope.$ctrl.handleClick()">log</button>' }

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

Updating database through AJAX calls does not work

I'm currently developing a system that requires the ability to remove employees from their Saturday shifts. This process involves clicking on an icon that triggers the JavaScript function "removeEmpFromSaturday" and passes relevant parameters. Within ...

"Oops, it seems like there are an excessive number of connections in Express MySQL causing

While programming in Angular and creating an API server in Express, I encountered a minor issue after spending hours coding and making requests to the API. The problem arises when the maximum number of requests is reached, resulting in an error. Everythin ...

Is there a way to make this AngularJS service wait until it has a value before returning it?

Multiple controllers call a service that loads data into an object named categories: .service('DataService', ['$http', '$q', function($http, $q) { var categories = {}; // Public API. return({ setCategory ...

Error: The function jQuery(...).hexColorPicker does not exist

I am attempting to utilize a color-picker jQuery plugin. Below is a screenshot of the JavaScript file: https://i.stack.imgur.com/ovRjx.png Here is the code I am using to initialize it: <script type="text/javascript> jQuery(function(){ ...

Type of Angular Service Issue: string or null

I'm encountering a persistent issue with my Angular code, specifically while calling services in my application built on Angular 13. The problem arises when trying to access the user API from the backend, leading to recurrent errors. Despite extensive ...

Setting up a specific print media query for the body element through JavaScript

I'm facing an issue with my web page that has a bootstrap modal which pops up when a button is clicked. I've added a print media query to print the content of the modal, but it's causing a problem. When I include the media query in the CSS, ...

Alter the border color of a bootstrap-div using JavaScript

I need to update the border color of a div element, but I'm encountering issues when using a bootstrap class on the div. Is there a way to change the border color using Javascript? <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/ ...

Is it possible for React Server Side rendering to be re-rendered on the client side?

In this demonstration of isomorphic rendering found at https://github.com/DavidWells/isomorphic-react-example, the author showcases Server Side Rendering by disabling Javascript. However, if JavaScript is enabled on the frontend, does it trigger a re-rende ...

My eCommerce website is currently experiencing some technical difficulties that need to be addressed

I'm in need of assistance with a particular error I encountered. I was following an ecommerce example application and everything seemed to be going smoothly until I clicked on "Shop Now." At that point, I received the following message: Server Error T ...

Can Jquery be used to swap out specific li content?

<div class="widget_ex_attachments"> <ul> <li> <i class="fa fa-file-word-o"></i> <a href="uploads/2014/09/Parellel-universe.docx">Parellel universe</a> </li> ...

javascript code producing incorrect HTML

I created a script to populate a selectbox with various options. Initially, the data is in the form of a string like this: "key=value;key2=value2;etc...": //splitting the string to separate different options for the selectbox var values = data.split(&apo ...

Storing account information in a .env file can be a more secure option compared to storing it in a client

Working on a basic nodejs application using express for file processing operations. Planning to package the final app with pkg. I need to implement a login system and one time account creation. The app will launch a browser tab running a vuejs UI app. Cons ...

JavaScript code does not run when a page is being included

On my AngularJS-based page, I have included some additional HTML pages like this: <div data-ng-include src="includehtml"></div> Here is the JavaScript code: $scope.selectImage = function(id) {$scope.includehtml = id;} (I pass the HTML file ...

Trouble embedding iframes in local files?

I have recently created a file which includes the following code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8> <style> iframe { height: 500px; width: 600px; } ...

Strange symbols keep appearing in my output from PHP

My current task involves generating a SQL query based on some inputs. I have a predefined SQL statement, in which I perform certain replacements, that will use these inputs to generate the required SQL through an ODBC connection. For now, I have stored th ...

Tips for creating boxes with clearly defined edges on shared sides using three.js

When I draw boxes with common sides, I don't see the common edges, but rather perceive them as a single object even though there are 25 boxes: https://i.sstatic.net/gE8FW.png function box(scene, x, y, z, size) { const points = []; ...

Unable to access setRowData() in AgGrid/Angular 2 leads to rendering of the grid without displaying any rowData

Resolved I think my solution is temporarily fixed and it reveals that I may have set up my mongoose model incorrectly. The answer provided did assist me in solving my issue, but ultimately the reason for the empty data rows was due to incorrect identifier ...

Bringing in a script and invoking a function on a specific variable

As a newcomer to Typescript, I've been experimenting with some code I came across online to enhance the appearance of links on my website. <script src="https://wow.zamimg.com/widgets/power.js"></script> <script>var wowhead_tooltips ...

What is the best way to pass variables between nested directives?

When a directive called el2 is nested within another directive called el1, I face challenges in accessing variables that are "locally declared" in el1 (such as variables generated by ng-repeat, ng-init, etc) from el2. For a practical example showcasing th ...

What is the best way to thoroughly uninstall Ionic and Cordova from an Ubuntu system?

Is there a way to completely remove Cordova and Ionic 1 and all of their dependencies from my Ubuntu system? And how can I reinstall them again? I found this blog helpful for installing Ionic and its dependencies: I attempted to uninstall Cordova and Ion ...