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:
actionBegin
,
actionComplete
,
and select
events.SelectEventArgs
in the
select event, and display the selected list item text in the event trace panel while selecting list items.<h4 id="evt-text">
<b>Event Trace</b>
</h4>
<div id="list-container">
<!-- ListView element -->
<ejs-listview id="listview-def" dataSource="(IEnumerable<object>)ViewBag.dataSource" actionComplete="onActionComplete" actionBegin="onActionBegin" select="onSelect" width="250">
</ejs-listview>
<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 -->
<ejs-button id="clear"><e-content-template>Clear</e-content-template></ejs-button>
</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> 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();
}
}
}