hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
105 stars 55 forks source link

Tooltips in icon column #124

Open mayraGL opened 6 years ago

mayraGL commented 6 years ago

Is there any way to add a tooltip to an icon inside a cell?

I tried to do it this way and this worked for me

<i class="icon-ok-sign" rel="tooltip" title="Key active" ></i>

but I would like to do it with mdTooltip (Angular Material) and it does not work

hjalmers commented 6 years ago

Hi @mayra268, you need to wrap it in a component. Here's an example that uses ngbTooltip and a service to fetch the description using the costType name.

import { Component, OnInit} from '@angular/core';
import {GtCustomComponent} from "@angular-generic-table/core";
import {CostTypeService} from '../../services/cost-type.service';
import {Observable} from 'rxjs/Observable';

@Component({
  selector: 'cost-type',
  template: `
    <span ngbTooltip="{{costTypeDescription | async}}">{{row.costType}} </span>
  `,
  styles: [
    `span {
      cursor:help;
    }`
  ]
})
export class CostTypeComponent extends GtCustomComponent<any> implements OnInit  {

  costTypeDescription:Observable<string>;
  constructor(private costTypeService:CostTypeService) {
    super();
  }

  ngOnInit() {
    this.costTypeDescription = this.costTypeService.getDescription(this.row.costType);
  }

}

And the field config:

fields: [ ...
{
  name: 'Cost type',
  objectKey: 'costType',
  columnComponent = {
    type: CostTypeComponent
  }
}]