|
App.component.html
<ejs-tooltip
#tooltip
target=".e-rowcell"
(beforeRender)="beforeRender($event)"
>
<ejs-grid [dataSource]="data" height="350">
<e-columns>
<e-column
field="OrderID"
headerText="Order ID"
width="120"
textAlign="Right"
></e-column>
<e-column
field="CustomerID"
headerText="Customer Name"
width="150"
></e-column>
<e-column
field="ShipCountry"
headerText="Ship Country"
width="150"
></e-column>
</e-columns>
</ejs-grid>
</ejs-tooltip>
app.component.ts
export class AppComponent {
public data: Object[] = [];
@ViewChild("tooltip", null)
public tooltip: TooltipComponent;
ngOnInit(): void {
this.data = hierarchyOrderdata;
}
beforeRender(args) {
//change the tooltip content
this.tooltip.content = args.target.closest("td").innerText;
}
}
|
|
[app.component.ts]
dataBound(args) {
// render the tooltip control in the grid content
this.tooltip = new Tooltip(
{ target: ".e-rowcell"}, // set the target so tooltip shown only target elements
this.grid.element.getElementsByClassName("e-gridcontent")[0] as any
);
// add the mouseover event to the grid content
this.grid.element.getElementsByClassName("e-gridcontent")[0].addEventListener("mouseover", this.contentmouseover.bind(this));
}
contentmouseover(args) {
var rowInfo = this.grid.getRowInfo(args.target.closest("td"));
var column = rowInfo.column;
// change the tooltip content based on the target element.
this.tooltip.content = rowInfo.rowData[(rowInfo.column as any).field ].toString();
}
|