Contact Support
Trace all events in ListView in Vue ListView component
19 Feb 202510 minutes to read
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:
-
Render the ListView with dataSource, and bind the
actionBegin
,actionComplete
, andselect
events. -
Perform custom operations in
actionBegin
,actionComplete
, and select events. -
Provide event log details for
actionBegin
andactionComplete
events, and they will be displayed in the event trace panel when the ListView action starts and the dataSource is bound successfully. -
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. -
Use the clear button to remove event trace information.
<template>
<div id="sample">
<div class="content-wrapper">
<!-- ListView element -->
<ejs-listview id='listview-def' ref='listviewInstance' :dataSource='data' width=250 :actionBegin='onBegin'
:actionComplete='onComplete' :select='onSelect'>
</ejs-listview>
</div>
<div id="list_event">
<h4><b>Event Trace</b></h4>
<div id="evt">
<div class="eventarea" style="height:273px;overflow: auto">
<span ref='EventLogEle' class="EventLog" id="EventLog" style="word-break: normal;"></span>
</div>
<div class="evtbtn">
<ejs-button id="clear" @click='onClick'>Clear</ejs-button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ListViewComponent as EjsListview } from "@syncfusion/ej2-vue-lists";
import { ButtonComponent as EjsButton } from "@syncfusion/ej2-vue-buttons";
import { ref } from 'vue';
const EventLogEle = ref(null);
const 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" }
]
const onBegin = () => {
appendElement("<b>actionBegin </b> event is triggered<hr>");
};
const onComplete = () => {
appendElement("<b>actionComplete</b> is triggered <hr>");
};
const onSelect = (args) => {
appendElement(args.text + "<b> is selected</b><hr>");
};
const appendElement = (html) => {
let span = document.createElement("span");
span.innerHTML = html;
let log = EventLogEle.value;
log.insertBefore(span, log.firstChild);
};
const onClick = () => {
EventLogEle.value.innerHTML = "";
};
</script>
<style>
#EventLog b {
color: #388e3c;
}
#listview-def {
border: 1px solid #dcdcdc;
}
.content-wrapper {
padding-left: 40px;
padding-top: 36px;
}
.evtbtn {
margin-top: 40px;
margin-left: 70px;
}
/* csslint ignore:start */
hr {
margin-top: 6px !important;
margin-bottom: 6px !important;
}
/* csslint ignore:end */
#evt {
border: 1px solid #dcdcdc;
padding: 10px;
min-width: 10px;
}
#sample {
display: inline-flex;
}
.eventarea {
min-width: 250px;
}
#list_event {
margin-top: -25px;
padding-left: 40px;
min-width: 200px;
}
</style>
<template>
<div id="sample">
<div class="content-wrapper">
<!-- ListView element -->
<ejs-listview id='listview-def' ref='listviewInstance' :dataSource='data' width=250 :actionBegin='onBegin'
:actionComplete='onComplete' :select='onSelect'>
</ejs-listview>
</div>
<div id="list_event">
<h4><b>Event Trace</b></h4>
<div id="evt">
<div class="eventarea" style="height:273px;overflow: auto">
<span ref='EventLogEle' class="EventLog" id="EventLog" style="word-break: normal;"></span>
</div>
<div class="evtbtn">
<ejs-button id="clear" @click.native='onClick'>Clear</ejs-button>
</div>
</div>
</div>
</div>
</template>
<script>
import { ListViewComponent } from "@syncfusion/ej2-vue-lists";
import { ButtonComponent } from "@syncfusion/ej2-vue-buttons";
export default {
name: "App",
components: {
"ejs-listview": ListViewComponent,
"ejs-button": ButtonComponent
},
data: function () {
return {
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" }
]
};
},
methods: {
onBegin: function () {
this.appendElement("<b>actionBegin </b> event is triggered<hr>");
},
onComplete: function () {
this.appendElement("<b>actionComplete</b> is triggered <hr>");
},
onSelect: function (args) {
this.appendElement(args.text + "<b> is selected</b><hr>");
},
appendElement: function (html) {
let span = document.createElement("span");
span.innerHTML = html;
let log = this.$refs.EventLogEle;
log.insertBefore(span, log.firstChild);
},
onClick: function () {
this.$refs.EventLogEle.innerHTML = "";
}
}
}
</script>
<style>
#EventLog b {
color: #388e3c;
}
#listview-def {
border: 1px solid #dcdcdc;
}
.content-wrapper {
padding-left: 40px;
padding-top: 36px;
}
.evtbtn {
margin-top: 40px;
margin-left: 70px;
}
/* csslint ignore:start */
hr {
margin-top: 6px !important;
margin-bottom: 6px !important;
}
/* csslint ignore:end */
#evt {
border: 1px solid #dcdcdc;
padding: 10px;
min-width: 10px;
}
#sample {
display: inline-flex;
}
.eventarea {
min-width: 250px;
}
#list_event {
margin-top: -25px;
padding-left: 40px;
min-width: 200px;
}
</style>