Search results

Data Binding in Blazor ListView component

ListView provides an option to load the data either from local dataSource or remote data services. This can be done through the dataSource property that supports the data type of array or DataManager.

ListView supports different kind of data services such as OData, OData V4, and Web API, and data formats like XML, JSON, and, JSONP with the help of DataManager Adaptors.

Fields Type Description
Id string Specifies ID attribute of list item, mapped in dataSource.
Text string Specifies list item display text field.
IsChecked string Specifies checked status of list item.
IsVisible string Specifies visibility state of list item.
Enabled string Specifies enabled state of list item.
IconCss string Specifies the icon class of each list item that will be added before to the list item text.
Child string Specifies child dataSource fields.
Tooltip string Specifies tooltip title text field.
GroupBy string Specifies category of each list item.
SortBy string Specifies sorting field, that is used to sort the listview data.
HtmlAttributes string Specifies list item html attributes field.

When complex data bind to ListView, you should map the ListViewFieldSettings properly. Otherwise, the ListView properties remain as undefined or null.

Bind to local data

Local data can be represented in two ways, they are as follows:

  • Array of simple data.
  • Array of JSON data.

Array of simple data

ListView supports to load the array of primitive data like string and numbers. Here, both value and text field act as same.

<SfListView DataSource="@StringData"></SfListView>

    string[] StringData = new string[] { "Artwork", "Abstract", "Modern Painting", "Ceramics", "Animation Art", "Oil Painting" };

ListView - Simple Data

Array of JSON data

ListView can generate its list items through an array of complex data. To get it work properly, you should map the appropriate columns to the field property.

@using Syncfusion.Blazor.Lists
<SfListView DataSource="@Data">
    <ListViewFieldSettings Id="Id" Text="Text"></ListViewFieldSettings>

@code {
   public string HeaderTitle = "ListView";

    List<DataModel> Data = new List<DataModel>();

    protected override void OnInitialized()
        Data.Add(new DataModel { Text = "Hennessey Venom", Id = "list-01" });
        Data.Add(new DataModel { Text = "Bugatti Chiron", Id = "list-02" });
        Data.Add(new DataModel { Text = "Bugatti Veyron Super Sport", Id = "list-03" });
        Data.Add(new DataModel { Text = "SSC Ultimate Aero", Id = "list-04" });
        Data.Add(new DataModel { Text = "Koenigsegg CCR", Id = "list-05" });
        Data.Add(new DataModel { Text = "McLaren F1", Id = "list-06" });
        Data.Add(new DataModel { Text = "Aston Martin One- 77", Id = "list-07" });
        Data.Add(new DataModel { Text = "Jaguar XJ220", Id = "list-08" });
        Data.Add(new DataModel { Text = "McLaren P1", Id = "list-09" });
        Data.Add(new DataModel { Text = "Ferrari LaFerrari", Id = "list-10" });

    class DataModel
        public string Id { get; set; }
        public string Text { get; set; }


Output be like the below.

ListView - Local Data

Bind to remote data

The ListView supports to retrieve the data from remote data services with the help of DataManager control. The Query property allows to fetch data and return it to the ListView from the database.

In the following sample, first 6 products from the Product table of NorthWind data service are displayed.

@using Syncfusion.Blazor.Lists
@using Syncfusion.Blazor.Data

<SfListView  HeaderTitle="Products" ShowHeader="true" TValue="Data" Query="@query">
    <ListViewFieldSettings Id="ProductID" Text="ProductName"></ListViewFieldSettings>
    <SfDataManager Url="" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>

@code {

    public static List<string> column = new List<string>()
    Query query = new Query().From("Products").Select(column).Take(6);
    public class Data
        public string ProductID { get; set; }
        public string ProductName { get; set; }

Output be like the below.

ListView - Remote Data