srikanth
srikanth

Reputation: 85

How to add hyperlink in ng2-smart-table in angular6

enter image description here

Want to add hyper link in request id column. Can you please help how to add? I am using Ng2-smart-table with Angular6

Upvotes: 0

Views: 3535

Answers (1)

Sachin Shah
Sachin Shah

Reputation: 4533

You can do that in simple way like this.

Let's assume you have called API and got data like this.

data = [
   {
      fname:'sachin',
      lname:'shah'
   },
   {
      fname:'banty',
      lname:'shah'
   }
]

When you got this data you have to use for loop. And you have to update your table settings.

import { LocalDataSource } from 'ng2-smart-table';

source: LocalDataSource; // Add this above constructor 

// Update settings like this.. 

columns: {        
    user: {
      title: 'Name' ,
      type: 'html'      //  <---- hear you have to pass html as a type... 
    },

var temp : any =  [];
  for(let i = 0 ; i < res.data.length ; i++){
    var obj = {
      name:'<a href="'+res.data[i].fname+'">Link</a>',          
      ... ... ...
    }
    temp.push(obj);        
  }      
  this.source = new LocalDataSource(temp); 

Hear I have attached my working code's screen shot.
Link works in column

Upvotes: 3

Related Questions