Search results

Trace events of listview in JavaScript (ES5) ListView control

08 May 2023 / 2 minutes to read

The ListView control triggers events based on its actions. The events can be used as extension points to perform custom operations. Refer to the following steps to trace the ListView events:

  1. Render the ListView with dataSource, and bind the actionBegin, actionComplete, and select events.
  2. Perform custom operations in actionBegin, actionComplete, and select events.
  3. Provide event log details for actionBegin and actionComplete events, and they will be displayed in the event trace panel when the ListView action starts and the dataSource bound successfully.
  4. Get the selected item details from the SelectEventArgs in the select event, and display the selected list item text in the event trace panel while selecting list items.
  5. Use clear button to remove event trace information.
Copied to clipboard
var data = [
        { 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" },
        { text: "Aston Martin One- 77", id: "list-07" },
        { text: "Jaguar XJ220", id: "list-08" },
        { text: "McLaren P1", id: "list-09" },
        { text: "Ferrari LaFerrari", id: "list-10" }
    var clear = new ej.buttons.Button();
    //Initialize ListView component
    var listObj = new ej.lists.ListView({
        //Set defined data to dataSource property
        dataSource: data,
        actionBegin: onActionBegin,
        actionComplete: onActionComplete,
        select: onSelect,
        width: "250"
    //Render initialized ListView component
    //Clears the event log details
    document.getElementById("clear").onclick = function () {
        document.getElementById("EventLog").innerHTML = "";
    //Handler for actionBegin event trace
    function onActionBegin() {
        appendElement("<b>actionBegin </b> event is triggered<hr>");
    //Handler for select event trace
    function onSelect(args) {
        appendElement(args.text + "<b>&nbsp;&nbsp;is selected</b><hr>");
    //Handler for actionComplete event trace
    function onActionComplete() {
        appendElement("<b>actionComplete</b> is triggered <hr>");
    //Display event log
    function appendElement(html) {
        var span = document.createElement("span");
        span.innerHTML = html;
        var log = document.getElementById("EventLog");
        log.insertBefore(span, log.firstChild);
Copied to clipboard
<!DOCTYPE html><html lang="en"><head>
    <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">
<script src="" type="text/javascript"></script>

    <div id="container">
        <h4 id="evt-text">
            <b>Event Trace</b>
        <div id="list-container">
            <!-- ListView element -->
            <div id="listview-def" tabindex="1">
            <div id="list_event">
                <div id="evt">
                    <div class="eventarea" style="height:273px;overflow: auto">
                        <!-- Event log element -->
                        <span class="EventLog" id="EventLog" style="word-break: normal;"></span>
                    <div class="evtbtn">
                        <!-- clear button element -->
                        <input id="clear" type="button" value="Clear">

var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>
Copied to clipboard
#container {
  visibility: hidden;

#loader {
  color: #008cff;
  height: 40px;
  width: 30%;
  position: absolute;
  font-family: "Helvetica Neue", "calibiri";
  font-size: 14px;
  top: 45%;
  left: 45%;

#list-container {
  max-width: 600px;
  margin: auto;

#EventLog b {
  color: #388e3c;

#listview-def {
  display: inline-block;
  border: 1px solid #dcdcdc;

.evtbtn {
  margin-top: 40px;
  margin-left: 70px;

#evt {
  border: 1px solid #dcdcdc;
  padding: 10px;
  width: 250px

#list_event {
  padding-left: 40px;
  display: inline-block;
  vertical-align: top;