|
@using Syncfusion.Blazor.Lists
@inject IJSRuntime jsRuntime
@using Newtonsoft.Json;
<div id="container">
<div id="sample">
<SfListView ID="list" DataSource="@DataSource" ShowCheckBox="true">
<ListViewFieldSettings Id="Id" Text="Name"></ListViewFieldSettings>
<ListViewEvents Selected="@OnSelected" TValue="ListDataModel"></ListViewEvents>
<ListViewTemplates TValue="ListDataModel">
<Template>
<a target='_blank' rel='nofollow' href="@((context as ListDataModel).Url)">
@((context as ListDataModel).Name)
</a>
</Template>
</ListViewTemplates>
</SfListView>
</div>
</div>
@code
{
List<ListDataModel> DataSource = new List<ListDataModel>() {
new ListDataModel {
Id = "1",
Name = "Google",
Url = "https://www.google.com"
},
…
….
new ListDataModel {
Id = "5",
Name = "AOL.com",
Url = "https://www.aol.com"
}
};
public async Task OnSelected(SelectEventArgs<ListDataModel> args)
{
//serailize the select event arg
var value = JsonConvert.SerializeObject(args.Event);
Dictionary<string, dynamic> eventParameters = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(value);
// serialize selected item data
var data = JsonConvert.SerializeObject(args.Data);
Dictionary<string, dynamic> argsData = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(data);
await jsRuntime.InvokeAsync<string>("accessDOMElement", eventParameters, argsData);
}
…
..
} |
|
<script>
function accessDOMElement(args, data) {
// get listview component instance
var listObj = document.getElementById("list").ej2_instances[0];
var elem = document.elementFromPoint(args.clientX, args.clientY);
if (elem.classList.contains("e-list-text")) {
// remove the active and focus class
elem.parentElement.parentNode.classList.remove("e-active", "e-focused");
// uncheck the item
listObj.uncheckItem(elem.parentElement.parentNode);
} else if (elem.classList.contains("e-text-content")) {
// remove the active and focus class
elem.parentElement.classList.remove("e-active", "e-focused");
// uncheck the item
listObj.uncheckItem(elem.parentElement);
}
// navigate to the url
document.location.rel='nofollow' href = data.Url;
}
</script> |
|
Description |
Link |
|
Getting started |
|
|
Data Binding |
|
|
Selected items |
|
|
API reference |