question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Delete button in a column through cell template not working

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior

Currently no demo shows action buttons.

Expected behavior

Atleast one demo should show how action buttons like Edit/Delete can be added to a cell template. Reproduction of the problem

Here is my use case

I have created a Angular 2 component and encapsulated ngx-datagrid into it. I accept json data & column config from parent component.

What is currently happening is

I want to show action buttons in last column. But they don’t show up in template.

Following is my code

datagrid-component.html file (reusable component’s template)

<i class=“search-icon” (click)=‘updateFilter($event)’> </div> <div class="border-color"> <ngx-datatable class=“data-grid material” headerHeight=“45” #table [columnMode]=“‘flex’” [rows]=“rowsToDisplay” [scrollbarV]=“true” [sorts]=“defaultSort” [rowHeight]=“45”> <ngx-datatable-column name=“{{column.name}}” *ngFor=“let column of columns;” [width]=“195” [flexGrow]=“column.flexGrow”> {{ column.cellTpl }} </ngx-datatable-column> </ngx-datatable> </div>

</div> =================================================

feature-component.html(Component for a feature uses grid component)

<div class="tenant-container"> <div class="tenant-header"> <div class="col-md-12"> <label class="title-tenant">Tenants</label> <app-add-tenant-modal></app-add-tenant-modal> </div> </div> <app-data-grid [data]="tenants" [columns]="_columns" [defaultSort]="_defaultSort"></app-data-grid> </div> =================================================

feature-component.ts

import { Component, OnInit } from ‘@angular/core’; import { Response } from ‘@angular/http’;

@Component({ selector: ‘feature’, templateUrl: ‘./feature.component.html’, styleUrls: [‘./feature.component.less’] }) export class FeatureComponent implements OnInit {

_columns: any[]; _defaultSort: any;

constructor( ) { }

ngOnInit() { this._columns = [ { prop: ‘column1’, name: ‘Column 1’, flexGrow: 1, cellTpl: <ng-template let-value="value" ngx-datatable-cell-template> <span tooltip="{{value.length > 30 ? value : null}}" placement="bottom" container="body">{{value}}</span> </ng-template> }, { prop: ‘column1’, name: ‘Column 1’, flexGrow: 1, cellTpl: <ng-template let-value="value" ngx-datatable-cell-template> <button>Edit</button><button>Delete</button> </ng-template> }];

====================================================

Like mentioned above, I have _columns property which gets passed down to datagrid component. But in data grid component, cellTpl is not rendered for actions columns.

How to do this ???

Can we have a column which doesn’t map to any data/key in response from server ???

What is the motivation / use case for changing the behavior?

It’s very commonly done

Please tell us about your environment:

Windows 7, Sublime

  • Table version: 0.8.x

latest

  • Angular version: 2.0.x

2.x

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

all

  • Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bhushangahirecommented, Sep 27, 2017

Any luck on this?

0reactions
ThommyTheThirdcommented, Feb 21, 2018

I’ll be honest: I haven’t read the whole discussion, but I’d like to drop my implementation as having custom action buttons (optionally, multiple, etc) was one of my needs as well.

I provide an array of a custom class I called DatatableButtons, which basically features an icon and an action callback. In the ngOnInit and other key moments I process these values and provide the ngx-datatable with an array of column definitions that include the “button columns”

for (let db of this.buttons) {
        let buttonColumn = {
        name: '',
        prop: db.id,
        button: db,
        cellTemplate: this.buttonTmpl
    };

    columns.push(buttonColumn);
}

In the html a buttonTmpl template is defined where the button’s icon will be rendered, and we can access the row/column/value there to extract the icon (note I put my entire custom button object in the column object, and use this in the html to extract its icon)

<ng-template #buttonTmpl let-row="row" let-value="value" let-button="column.button">
    <span class="glyphicon glyphicon-{{button.icon}}"></span>
</ng-template>

To give you an example of a button implementation:

public buttons: DatatableButton[] = [
      {
          action: this.logYourself.bind(this),
          icon: 'trash'
      }
  ];

Where the logYourself function is in the component using the datatable, and I bind it to this so that I can use the correct this in the function’s scope.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Edit / Delete" button for each row & header column is 'Action ...
i'm need to achieve the same functionality of action buttons but my material table is in a custom component, i'm unable to figure...
Read more >
Delete button not working when editing row in UI for WPF
I'm trying to create a column with a delete button that the user will use ... click into a different cell and then...
Read more >
Add or remove rows and columns in Numbers on Mac
In Numbers on your Mac, add, delete, rearrange, or hide rows and columns in a table, and freeze header rows.
Read more >
Add, edit, find, and delete rows by using a data form
When a row of data is very wide and requires repeated horizontal scrolling, consider using a data form to add, edit, find, and...
Read more >
3 ways to remove spaces between words / numbers in Excel ...
Remove all spaces between numbers · Press Ctrl + Space to select all cells in a column. · Press Ctrl + H to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found