Geek Culture
Published in

Geek Culture

Angular:Adding BootStrap PopOvers and ToolTips with Dynamic Data to an Ag-Grid Table

I always preferred the ngx-bootstrap npm module for adding any bootstrap component to my Angular Application. The reason being, it doesn’t require adding any Jquery code in the components nor any complex setup.

I am taking a very simple example of displaying a list of authors and the books those authors have written in an Ag-Grid table.I have used this example multiple times in the past and am going to use it again to demonstrate ToolTips and PopOvers :)

Below is the data that we are going to use. Its an array of objects exported from books.ts

Each object describes the type of book, a few authors who have written books in that genre,some information about the author,an image of the author,the books they have written, and the price of each book.

These are our objectives:

  1. Populate the above data in a Ag-Grid Table as below. We have displayed the BookType and the list of Authors who have written books under that particular BookType. On clicking on a particular author,we are displaying a few books that the author has written.

The focus of the story will not be on how the data is displayed on the table using <ng-template>.This is out of the scope of the story. If you want to understand this concept, you can checkout the below 2 stories.

2. We are displaying an information icon next to each author’s name and also next to each book name. On hovering over the icon next to the author name, we shall display a popover showing few lines about the author and also an image of the author. The popover disappears only when we click somewhere outside the popover.

On clicking on the icon next to the book name,we are displaying a tooltip showing the price of the book. The tooltip disappears when we click on the icon again.

PopOver showing the author details and image
ToolTip showing the price of the book

Below are the dependencies installed in the package.json.

package.json

This is how we have added PopoverModule and the TooltipModule from the ngx-bootstrap to the application.

AppModule

Below is a screenshot of the angular.json, where we have imported the bootstrap,jquery and popper.js libraries.

angular.json

Below is the PopOver Template that we shall apply to the Author Names in the table. The template has the reference popOverIcon. The data passed to this template will be names of the authors, few lines on the author and a url containing the image of the author.

Below is the ToolTip template that we shall apply to each book name. The template has a reference toolTipIcon. The data passed to this template will contain the price of each book.

Now let’s check how these templates will be used in the table. We are using FormArrays and FormGroups to display the table data.

Below is a small snippet taken from the component template where we are using radio buttons next to the Author names in the table.We have passed the template reference popOverIcon to the ngTemplateOutlet property and the data to be displayed in the PopOver in the ngTemplateOutletContext property.

Similarly we have applied the ToolTip template in the below part of the component template where the radio buttons next to the book names are being displayed. We have passed the template reference toolTipIcon to the ngTemplateOutlet property and the data to be displayed in the PopOver in the ngTemplateOutletContext property.

Please check the below link to see the entire working example.

--

--

--

A new tech publication by Start it up (https://medium.com/swlh).

Recommended from Medium

How to implement drag and drop lists in Angular 6 application?

Get persistance in linux by backdooring vscode/vscodium

Writing async safe code: walkthrough

Make your S3 hosted React App Secure

Implementing Dynamic Template Driven Forms in Angular

Create Cross-platform Voice Applications With Jovo

3 Postman Hacks For Writing Tests Faster

A gentle but exhaustive intro to ES6.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AngularEnthusiast

AngularEnthusiast

Loves Angular and Node

More from Medium

Angular: Using different ToolTip Templates for every column in an Ag-Grid Table

I have created component server display.

Simple Toast Notification in Angular

Lazy loading with Angular