Trouble with displaying cell content in ag-grid within an Angular application

I have implemented ag-grid in my Angular project and I am trying to redirect to a link when a specific cell is clicked.

Currently, I have a new value coming from an API which is nested inside an object in an array. For example, the object is dto-> dataitems[shortName], which I am displaying in the first column. However, I want to redirect the user to a router link when they click on this cell.

I attempted the following code but it did not work:

component.ts file:

 headerName: 'Deal Name',
          autoHeight: true,
          colId: 'shortName',
          field: 'shortName',
          exportColumn: true,
          width: 275,
          cellRendererFramework: function(params) {
            return '<a href="javascript:void(0)"'+
             '[routerLink]="[/valuation,'+
              '{deal: test,'+
              'b: 2020Q3,'+
              'c: someval,'+
              'd: 9'+
               '}]"' +
             'target="_blank" rel = "noopener">'+params.value+'</a>'
          },

Although the above code displays the value, clicking on the link does not work as expected.

I also tried using ng-template with the code below, however, when I add my column, it shows a blank value:

html :

<ng-template #dealNameCell let-row>
      <a
        *ngIf="row.canView"
        href="javascript:void(0)"
        [routerLink]="[
          '/valuation',
          {
          deal: row.someval,
          b: row.someval,
          c: row.someval,
          d: row.someval
         }
        ]"
        queryParamsHandling="merge"
      >
        {{ row.shortName }}
      </a>

      <a
        data-toggle="modal"
        data-target="#changeQuarterModal"
        *ngIf="!row.canView"
        href="javascript:void(0)"
        queryParamsHandling="merge"
      >
        {{ row.shortName }}
      </a>
    </ng-template>

When using the above code, the column appears blank and no value is displayed. Adding columns that are at the root level of the object works fine. But the issue arises when trying to retrieve data nested inside an array within an object.

Answer №1

Using a cell renderer for navigation is definitely possible, just like any other component. In our projects, we typically define the base URL of the link within the component itself, such as link = '/accounts/users/', and then retrieve the necessary data via

link = '/accounts/users/'
linkText = params.value.linkText; 

agInit(params: any): void {
   this.link += params.value;
// Alternatively, if you have an array of link parameters:
// for(const linkSegment of params.value.linkValues) {
//  this.link += linkSegment + '/';
// }
}

Then, in the template, simply:

<a class="my-link" [routerLink]="link">{{params.linkText}}</a>

You could also choose to use router.navigate in the component for a different linking approach, but that's entirely up to you.

I hope this explanation proves helpful! Happy coding!

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

Tips for effectively handling the data received from a webservice when logging into a system

My web service provides me with permissions from my user. The permissions are stored as an array in JSON format. I need to find a way to access and display this data in another function. {"StatusCode":0,"StatusMessage":"Authenticated Successfully", "Token ...

Tips for including a clickable button in an Angular textarea

I am looking for a solution to float a button to the top right corner of a text area in an Angular application. Below is my current code setup, but unfortunately, it does not achieve the desired result: <textarea matInput matInput rows="15" cols="40" ...

Dragula drag and drop in a single direction with Angular 2 copy functionality

Attempting to utilize ng2 dragula for one-way drag and drop with copy functionality. Below is the template I am working with: `<div> <div class='wrapper'> <div class='container' id='no-drop' [dragula]=& ...

Does one require the express.js framework in order to create a web application using nodeJS?

Exploring the creation of a basic web application using HTML, NodeJS, and Postgres. Can this be achieved without incorporating the ExpressJS framework? Seeking guidance on performing CRUD operations with NodeJs, Javascript, and Postgres sans ExpressJS. G ...

How to update the page title in React TypeScript 16.8 without using Helmet

I have created a custom 404 not found page, and I would like the title of the page to change when someone navigates to it. Unfortunately, I do not want to use Helmet for this purpose, but I am struggling to make constructor or componentDidMount() work in ...

Is it possible to apply a formatting filter or pipe dynamically within an *ngFor loop in Angular (versions 2 and 4

Here is the data Object within my component sampleData=[ { "value": "sample value with no formatter", "formatter": null, }, { "value": "1234.5678", "formatter": "number:'3.5-5'", }, { "value": "1.3495", "formatt ...

I am retrieving data from a service and passing it to a component using Angular and receiving '[object Object]'

Searching for assistance with the problem below regarding my model class. I've attempted various approaches using the .pipe.map() and importing {map} from rxjs/operators, but still encountering the error message [object Object] export class AppProfile ...

Safari does not support RequestAnimationFrame in Angular 4

I'm currently working with material design in an Angular 4 project. However, I've encountered an issue where the project does not load properly on Safari due to an error related to RequestAnimationFrame. Does anyone know how to fix this problem? ...

When attempting to send a token from an account to a marketplace in ERC721, the transfer caller must either be the owner

Currently, I am in the process of transferring my NFT to a marketplace pragma solidity ^0.8.7; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; import & ...

A method for modifying the key within a nested array object and then outputting the updated array object

Suppose I have an array called arr1 and an object named arr2 containing a nested array called config. If the key in the object from arr1 matches with an id within the nested config and further within the questions array, then replace that key (in the arr1 ...

Ways to set a default value for a function that returns an unknown type in TypeScript

In my code, I have a customizedHook that returns a value of type typeXYZ || unknown. However, when I try to destructure the returned value, I encounter an error TS2339: Property 'xyz' does not exist on type 'unknown', even though the da ...

Guide to combining an Angular 2 (angular-cli) application with Sails.js

I am looking to integrate the app created using angular-cli with Sails.js. My background is in PHP, so I am new to both of these frameworks. What are the steps involved in setting them up together? How can I execute commands like ng serve and/or sails li ...

How do I select all checkboxes in TypeScript when I only click on one of them?

I'm currently working with a list of checkboxes in my HTML code: <div class="col-sm-12" *ngIf="ControllerModel"> <div *ngFor="let controller of ControllerModel" class="panel col-md-6 col-lg-6 col-xs-6"> <div class="panel-heading" ...

Angular nested innerHTML not evaluating ternary operator

Here is a code snippet that I am struggling with: {{ Name && Name.length > 20 ? (Name | slice: 0:20) + "..." : Name }} The above code works fine when used inside a div, but when I try to use it within innerHTML, I encounter a syntax e ...

Issue with Angular 2: Route remains unchanged when clicking back button despite view changes

Currently I am utilizing : "@angular/router": "3.0.0" An issue I am encountering is that upon pressing the back button of the browser, the view switches back to the previously loaded view, yet the route does not update. What could potentially be causing ...

What is the best method for converting an Object with 4 properties to an Object with only 3 properties?

I have a pair of objects: The first one is a role object with the following properties: Role { roleId: string; name: string; description: string; isModerator: string; } role = { roleId:"8e8be141-130d-4e5c-82d2-0a642d4b73e1", ...

I am looking to attach a Bootstrap 4 class to the form input field

I needed to apply the "is-invalid" bootstrap4 class when my Angular form field was invalid and touched. I attempted to achieve this with: <input type="text" #name class="form-control" [class.is-invalid]="name.invalid && name.touched" name="Name ...

Error in Angular 8: Module loading from "url" has been intercepted due to an unsupported MIME type ("text/html") being blocked

I have developed an application using Angular 8 and Node 12. When I try to open a new tab or reload the page after building Angular 8, I encounter an issue for which I have extensively searched online but found no solution. In the Firefox console, the er ...

Switch from flexbox layout to begin on the next column within the same row

I am attempting to create a CSS layout where, after a specific element like :nth-child(6), the elements will break and form a separate column within the same row. The parent element should split into 2 columns after every 6th element in the same row, then ...

How does TypeScript interpret the data type 'a' | 'b' as a string?

As a beginner in TypeScript, React, and English, I apologize for any confusion. I have written a function like this: interface ObjectAttrUniqueState { editVisible: boolean; currentId: number; selectedUnique: number[]; name: string; desc: string; ...