Hi
I have below columns data returned. I want if name = actions' then in row 2 button Edit & Delete should be displayed in Angular 17
Code
Columns are displayed like below
1:
name: "description"
title: "Description"Thanks
Hi
I have below columns data returned. I want if name = actions' then in row 2 button Edit & Delete should be displayed in Angular 17
Columns are displayed like below
1:
name: "description"
title: "Description"Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmeshwaran SRank #819 · 2.8K reputationPosted Jun 27, 2024, 10:29 AM EDT
To display buttons based on a specific condition, you can use Angular's templating features along with conditional logic in your component template. Here’s a step-by-step guide on how to achieve this:
*ngIfto conditionally display the buttons in your template.Step 1: Define the Data Structure
import { Component } from '@angular/core'; @Component({ selector: 'app-dynamic-table', templateUrl: './dynamic-table.component.html', styleUrls: ['./dynamic-table.component.css'] }) export class DynamicTableComponent { columns = [ { name: "description", title: "Description" }, { name: "actions", title: "Actions" } ]; rows = [ { description: "Item 1", actions: true }, { description: "Item 2", actions: true } ]; }Step 2: Create the Template
In your component's HTML file, use
*ngIfto conditionally display the buttons.Step 3: Define the Logic for Edit and Delete Buttons
In your component's TypeScript file, define the methods for
onEditandonDelete.import { Component } from '@angular/core'; @Component({ selector: 'app-dynamic-table', templateUrl: './dynamic-table.component.html', styleUrls: ['./dynamic-table.component.css'] }) export class DynamicTableComponent { columns = [ { name: "description", title: "Description" }, { name: "actions", title: "Actions" } ]; rows = [ { description: "Item 1", actions: true }, { description: "Item 2", actions: true } ]; displayedColumns: string[] = ['description', 'actions']; onEdit(row: any) { // Handle edit logic here console.log('Edit', row); } onDelete(row: any) { // Handle delete logic here console.log('Delete', row); } }