Radzen Professional is now 20% off until January 4th 2019! Learn more

DataGrid

This guide demonstrates how to use the DataGrid component.

Quick video

DataGrid Properties

Name Type Default Description
Name string ‘grid’ + index suffix Unique name of the DataGrid.
Data array null DataGrid data.
Count integer null DataGrid number of all records.
PageSize integer 10 DataGrid number of records per page.
AllowDelete boolean false Is records delete allowed.
AllowAdd boolean false Is adding of new records allowed.
AllowPaging boolean false Is paging allowed.
AllowSorting boolean false Is sorting allowed.
AllowMultiSorting boolean false Is multi sorting allowed.
AllowFiltering boolean false Is filtering allowed.
AllowScrolling boolean false Is scrolling allowed.
Visible boolean/expression true Is DataGrid visible.
EmptyText string No records to display. DataGrid text on no records.
Columns array of GridColumn empty DataGrid columns.
Template string null DataGrid row details template.

DataGrid Events

Name Type Default Description
RowSelect event null Row select event of the DataGrid. Fired when row is selected. Row data as event arguments.
RowDoubleClick event null Row double click event of the DataGrid. Fired when row is double clicked. Row data as event arguments.
RowExpand event null Row expand event of the DataGrid. Fired when row is expanded. Row data as event arguments.
RowCollapse event null Row collapse event of the DataGrid. Fired when row is collapsed. Row data as event arguments.
Add event null Add event of the DataGrid. Fired when Add button is pressed. No event arguments.
Delete event null Delete event of the DataGrid. Fired when Delete button is pressed. Row data as event argument.
LoadData event null Load data event of the DataGrid raised on page, sort and filter with info about the current page, page size, sorted columns and filter expressions in OData v4 format

GridColumn Properties

Name Type Default Description
Type string string GridColumn type. string, integer, number or boolean.
Format string null GridColumn format. int32, int64, float, double, byte, binary, base64, date, date-time, date-time-offset or password.
Property string null GridColumn property name.
SortProperty string null GridColumn sort property name. If not set Property will be used for sorting.
FilterProperty string null GridColumn filter property name. If not set Property will be used for filtering.
Title string null GridColumn title.
Template string null GridColumn template.
FooterTemplate string null GridColumn footer template.
Width number null GridColumn width in pixels.
Sortable boolean true Is sorting allowed for this column.
Filterable boolean true Is filtering allowed for this column.

Customizing the column appearance

By default the DataGrid component displays the value of the Property in a column. Use the Template property to customize the appearance. The whole data item is available as data in the expression.

Template examples:

  • <strong>${data.FirstName}</strong> - display the FirstName property in a <strong></strong> element.
  • Full Name: ${data.FirstName} ${data.LastName} - display two data item properties in the column.

Footer template

  • <b>TOTAL: ${totalUnitPrice | currency}</b> - display the total UnitPrice property in a <b></b> element.

You can apply calculations on current page data or all items using the following expression: ${result.value.map(p=>p.UnitPrice).reduce((a, b) => a + b)}. If you want the calculation to be applied on all items you can request them separately using for example $select parameter:

Angular declaration

  <rz-grid #grid0 addText="Add" [allowFiltering]="true" [allowPaging]="true" [allowSorting]="true" [count]="getProductsCount" [data]="getProductsResult" emptyText="No records to display." [pageSize]="10" (loadData)="grid0LoadData($event)">
    <rz-grid-column property="ProductID" title="Product ID" type="integer">
    </rz-grid-column>
    <rz-grid-column property="ProductName" title="Product Name" type="string">
    </rz-grid-column>
    <rz-grid-column property="QuantityPerUnit" title="Quantity Per Unit" type="string">
    </rz-grid-column>
    <rz-grid-column format="decimal" property="UnitPrice" title="Unit Price" type="number">
      <ng-template let-data gridColumnTemplate>
      {{data?.UnitPrice | currency}}
      </ng-template>
      <ng-template gridColumnFooterTemplate>
      <b>TOTAL: {{totalUnitPrice | currency}}</b>
      </ng-template>
    </rz-grid-column>
    <rz-grid-column format="int16" property="UnitsInStock" title="Units In Stock" type="integer">
      <ng-template let-data gridColumnTemplate>
      {{data?.UnitsInStock}}
      </ng-template>
      <ng-template gridColumnFooterTemplate>
      <b>TOTAL: {{totalUnitsInStock}}</b>
      </ng-template>
    </rz-grid-column>
    <rz-grid-column format="int16" property="UnitsOnOrder" title="Units On Order" type="integer">
    </rz-grid-column>
    <rz-grid-column format="int16" property="ReorderLevel" title="Reorder Level" type="integer">
    </rz-grid-column>
    <rz-grid-column property="Discontinued" title="Discontinued" type="boolean">
    </rz-grid-column>
  </rz-grid>

In-memory and server-side operations

DataGrid component can perform sorting, paging and filtering both in-memory and server-side.

  • For in-memory operations enable respective feature, add load event for the Page, call your service and set data property to returned value.

  • For server-side operations enable respective feature, add load event for the Page, call your service and set data and count properties to returned values, add loadData event handler, call your service again with provide information in the event argument and set again data and count properties to returned values. If you use New Data Dialog, Radzen will setup everything automatically.

Sorting and Filtering by lookup fields

DataGrid component can sort and filter by lookup fields by defining SortProperty and FilterProperty for desired column. When generating pages from OData V4, Microsoft SQL Server, MySQL or PostgreSQL, Radzen will set automatically SortProperty and FilterProperty for all lookup columns based on data-source relations.

Example request

http://services.radzen.com/odata/OrderDetails?$filter=contains(Product/ProductName,%20%27Ch%27)&$top=10&$skip=0&$orderby=Product/ProductName%20desc&$expand=Order,Product&$count=true

We are here for you

Making our users happy is always a priority for us.