Search results

Data binding

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.

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

@code{
    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.EJ2.Blazor.Lists
<EjsListView DataSource="@Data">
    <ListViewFieldSettings Id="Id" Text="Text"></ListViewFieldSettings>
</EjsListView>

@code {
   public string HeaderTitle = "Listview";

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

    protected override void OnInitialized()
    {
        base.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