Skip to content

Latest commit

 

History

History
238 lines (168 loc) · 10.4 KB

overview.md

File metadata and controls

238 lines (168 loc) · 10.4 KB
title page_title description slug tags published position
Overview
Grid Overview
The Blazor Grid provides a comprehensive set of ready-to-use features that cover everything - paging, sorting, filtering, editing and more.
grid-overview
telerik,blazor,grid,datagrid,overview
true
0

Blazor Grid Component Overview

This article provides a quick introduction to get your first Blazor data grid component up and running in a few seconds. There is a video tutorial and a list of the key features.

The Telerik Blazor Data Grid provides a comprehensive set of ready-to-use features that cover everything from paging, sorting, filtering, editing, and grouping to row virtualization, optimized data reading, keyboard navigation, and accessibility support.

The Telerik Blazor grid is built on native Blazor from the ground up, by a company with a long history of making enterprise-ready Grids. This results in a highly customizable Grid that delivers lighting fast performance.

Creating Blazor Grid

  1. Use the TelerikGrid tag.
  2. Assign the Grid Data parameter to an IEnumerable<T> property, or use the OnRead event. We'll go with Data this time. The Grid Data Binding article compares the two alternatives.
  3. (optional) Enable some data operations like paging, sorting or filtering.
  4. Add GridColumn instances under the GridColumns tag. Each column Field should point to the model property to display. Use nameof() or the plain field name. Define user-friendly column Titles or DisplayFormat for numeric and date values.

caption Get started with the Blazor Grid

@* Telerik Blazor Grid with some common features *@

<TelerikGrid Data="@GridData"
             Pageable="true"
             Sortable="true"
             FilterMode="@GridFilterMode.FilterRow">
    <GridColumns>
        <GridColumn Field="Name" Title="Product Name" />
        <GridColumn Field="Price" DisplayFormat="{0:C2}" />
        <GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" />
        <GridColumn Field="@nameof(Product.Discontinued)" />
    </GridColumns>
</TelerikGrid>

@code {
    private List<Product> GridData { get; set; }

    protected override void OnInitialized()
    {
        GridData = new List<Product>();

        var rnd = new Random();

        for (int i = 1; i <= 30; i++)
        {
            GridData.Add(new Product
            {
                Id = i,
                Name = "Product name " + i,
                Price = (decimal)(rnd.Next(1, 50) * 3.14),
                Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date,
                Discontinued = i % 5 == 0
            });

        }

        base.OnInitialized();
    }

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
        public DateTime Released { get; set; }
        public bool Discontinued { get; set; }
    }
}

Blazor Grid Video Tutorial

If you prefer video instructions, watch this short Blazor Grid video tutorial. It covers to following topics:

  • Introduction to the Telerik Blazor Grid
  • Add TelerikRootComponent to MainLayout
  • Add a Blazor Grid
  • Configure columns
  • Enable additional features
<iframe width="560" height="315" src="https://www.youtube.com/embed/NW2hHtmM2Gk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Data Binding

The are two main ways to provide data to the Grid - via the Data parameter and via the OnRead event. Data provides simplicity, while OnRead allows more flexibility in complex scenarios, and performance when there is a lot of data.

Data Operations

The Blazor Grid supports all fundamental data operations out-of-the-box:

  • Paging or alternatively, virtual scrolling
  • Sorting
  • Filtering
  • Grouping. The Grid can also load the data for each group on demand.
  • Aggregates

Editing

The Grid can perform CRUD operations on its current data - add, edit and delete rows. It exposes events that let you control the editing and commit changes to the actual data source.

The Grid offers several editing modes with different user experience - incell, inline and popup.

See Grid CRUD Operations Overview for more details.

Virtualization

The Blazor Grid features UI virtualization to improve browser performance:

  • Row virtualization
  • Column virtualization

Column Features

The Grid columns offer a rich set of functionality to enable immense flexibility for your application scenarios. The main column features include:

  • Display Format for numeric and date values
  • Resizing
  • Reodering
  • Column Menu to control data operations and column visibility
  • Frozen columns, which do not scroll horizontally (also called locked columns)
  • Multi-column Headers to group multiple column headers under a single parent header
  • Column Events
  • Visibility and Width

Templates

The Grid supports custom content in various parts of the component such as data cells, headers, footers, editors and more. See Grid Templates.

More Blazor Grid Features

  • Selection—select one or multiple rows through clicks or checkboxes or select one or multiple cells through clicks.
  • State—get or set the Grid configuration programmatically.
  • Toolbar—define user actions in a toolbar above the header cells.
  • Hierarchy—nest Grids and visualize parent-child relations between data records.
  • Drag and drop rows—move rows in a Grid or between different Grids.
  • Loading animation—show a loading animation to improve user experience during long data operations.
  • Scrolling—the Grid will show standard scrollbars automatically if the data does not fit the current component width and height.

Grid Parameters

The following table lists Grid parameters, which are not discussed elsewhere in the component documentation. Check the Grid API Reference for a full list of parameters, methods and events.

@template

Parameter Type and Default Value Description
Class string Additional CSS class for the <div class="k-grid"> element. Use it to apply custom styles or override the theme. For example, change the Grid font size.
Height string A height style in any supported CSS unit. You can also make the Grid height change automatically with the browser window.
Navigable bool Enables keyboard navigation.
Width string A width style in any supported CSS unit. The Grid has no default width, but expands horizontally to fill its container.

Blazor Grid Reference and Methods

The Grid has methods to execute actions such as:

  • rebind to refresh the data
  • export to Excel and other formats
  • automatically resize columns to fit their content
  • get or set the Grid configuration state
  • get the dragged data item and its drop index from the destination Grid instance

To execute these methods, obtain reference to the Grid instance via @ref.

caption How to obtain a Grid reference and call methods

<TelerikButton OnClick="@AutoFit">Autofit All Columns</TelerikButton>

<TelerikGrid @ref="TheGrid"
             Data="@GridData"
             Width="600px">
    <GridColumns>
        <GridColumn Field="@(nameof(GridModel.Id))" />
        <GridColumn Field="@(nameof(GridModel.Text))" Width="300px" />
    </GridColumns>
</TelerikGrid>

@code {
    private TelerikGrid<GridModel> TheGrid { get; set; }

    private async Task AutoFit()
    {
        await TheGrid.AutoFitAllColumnsAsync();
    }

    private IEnumerable<GridModel> GridData = Enumerable.Range(1, 5)
        .Select(x => new GridModel
            {
                Id = x,
                Text = "some longer text here that will not fit on a single line and we would like to expand it " + x
            });

    public class GridModel
    {
        public int Id { get; set; }
        public string Text { get; set; }
    }
}

Next Steps

  • Explore Grid data binding
  • Learn about Grid columns

See Also