Filter and search list items using listview in EJ2 TypeScript Listview control

8 Aug 20234 minutes to read

The filtered data can be displayed in the ListView control depending upon on user inputs using the DataManager. Refer to the following steps to render the ListView with filtered data.

  • Render a textbox to get input for filtering data.

  • Render ListView with dataSource, and set the sortOrder property.

  • Bind the keyup event for textbox to perform filtering operation. To filter list data, pass the list data source to the DataManager, manipulate the data using the executeLocal method, and then update filtered data as ListView dataSource.

import { ListView } from "@syncfusion/ej2-lists";
import { enableRipple } from "@syncfusion/ej2-base";
import { DataManager, Query } from "@syncfusion/ej2-data";
//Define an array of JSON data
let listData: { [key: string]: Object }[] = [
  { text: "Hennessey Venom", id: "list-01" },
  { text: "Bugatti Chiron", id: "list-02" },
  { text: "Bugatti Veyron Super Sport", id: "list-03" },
  { text: "SSC Ultimate Aero", id: "list-04" },
  { text: "Koenigsegg CCR", id: "list-05" },
  { text: "McLaren F1", id: "list-06" }

// Initialize the ListView control
let listObj: ListView = new ListView({
  //Set the defined data to the dataSource property
  dataSource: listData,
  //Map the appropriate columns to the fields property
  fields: { text: "text", id: "id" },
  //Set the sortOrder property
  sortOrder: "Ascending"
//Render the initialized ListView control

document.getElementById("textbox").addEventListener("keyup", onKeyUp);
//Here, the list items are filtered using the DataManager instance for ListView
function onKeyUp() {
  let value = (document.getElementById("textbox") as HTMLInputElement).value;
  let data: Object[] = new DataManager(listData).executeLocal(
    new Query().where("text", "startswith", value, true)
  if (!value) {
    listObj.dataSource = listData.slice();
  } else {
    listObj.dataSource = data as { [key: string]: Object }[];
<!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" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>
<script src="" type ="text/javascript"></script>

    <div id='loader'>Loading....</div>
    <div id="container">
        <div id="sample">
            <input class="e-input" type="text" id="textbox" placeholder="Filter" title="Type in a name">
            <div id="list"></div>


In this demo, data has been filtered with starting character of the list items. You can also filter list items with ending character by passing the endswith in where clause instead of startswith.