Search results

ListView with hyper-link navigation in JavaScript ListView control

08 May 2023 / 1 minute to read

We can use anchor tag along with href attribute in our ListView template property for navigation.

Copied to clipboard
let anchor_template: string = "<a target='_blank' href='${url}'>${name}</a>";

In the below sample, we have rendered ListView with search engines URL.

Copied to clipboard
import { ListView } from '@syncfusion/ej2-lists';

//Define an array of JSON data
let dataSource: { [key: string]: Object }[] = [
    { name: 'Google', url: '' },
    { name: 'Bing', url: '' },
    { name: 'Yahoo', url: '' },
    { name: '', url: '' },
    { name: '', url: '' }
let anchor_template: string = "<a target='_blank' href='${url}'>${name}</a>";

// Initialize ListView control
let listObj: ListView = new ListView({

    //Set defined data to dataSource property
    dataSource: dataSource,

    //Set header title
    headerTitle: 'Search engines',

    //Set true to show header title
    showHeader: true,

    template: anchor_template


//Render initialized ListView control
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

    <title>Essential JS 2 for ListView </title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for ListView UI Control" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>

    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>