Search results

Trace all events in ListView

The ListView component 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.

razor
list.cs
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Lists;
<h4 id="evt-text">
    <b>Event Trace</b>
</h4>

<div id="list-container">
    <!-- ListView element -->
    @Html.EJS().ListView("listview-def").DataSource((IEnumerable<object>)ViewBag.dataSource).ActionComplete("onActionComplete").ActionBegin("onActionBegin").Select("onSelect").Width("250").Render()
    <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>
            <div class="evtbtn">
                <!-- clear button element -->
                @Html.EJS().Button("clear").Content("Clear").Render()
            </div>
        </div>
    </div>
</div>

<style>
    #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;
    }
</style>
<script>

    //Clears the event log details
    document.getElementById("clear").onclick = () => {
        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);
    }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
    public class ListViewController : Controller
    {
        public IActionResult list()
        {
            List<object> listdata = new List<object>();
            listdata.Add(new { text= "Hennessey Venom", id= "1", icon= "delete-icon" });
            listdata.Add(new { text= "Bugatti Chiron", id= "2", icon= "delete-icon" });
            listdata.Add(new { text= "Bugatti Veyron Super Sport", id= "3", icon= "delete-icon" });
            listdata.Add(new { text= "Aston Martin One- 77", id= "4", icon= "delete-icon" });
            listdata.Add(new { text= "Jaguar XJ220", id= "list-5", icon= "delete-icon" });
            listdata.Add(new { text= "McLaren P1", id= "6", icon= "delete-icon" });
            ViewBag.dataSource = listdata;
            return View();
        }
    }
}