Skip to main content

Unbound Rows

  • 3 minutes to read

This topic describes the main concepts of using unbound rows within the VerticalGrid extension.

Unbound Rows Overview

The VerticalGrid supports bound and unbound rows. Bound rows obtain their data from a data source. Unbound rows are not bound to any field in a data source. These rows can be populated manually by handling the VerticalGridSettings.CustomUnboundRowData event or by specifying an expression using the VerticalGridDataRow.UnboundExpression property. The VerticalGrid uses the specified expression to calculate cell values for the current row. The Expressions section describes the syntax for creating expressions.

There is no difference between working with bound and unbound rows. You can sort, display summaries and filter unbound rows in the same manner as bound rows.

An unbound row meets the following requirements.

Providing Data for Unbound Rows

ASP.NET MVC VerticalGrid provides two approaches to generating data for unbound rows.

  • Using an Unbound Expression

    To provide unbound rows with data using unbound expressions, compose the expression based on a specific syntax, and assign this expression to the VerticalGridDataRow.UnboundExpression (through MVCxVerticalGridRow.UnboundExpression) property.

    The code sample below demonstrates how to add an unbound row that retrieves its data using an unbound expression.

    Partial View code:

    @Html.DevExpress().VerticalGrid(settings => {
        settings.Name = "VerticalGrid";
        settings.CallbackRouteValues = new { Controller = "Home", Action = "VerticalGridPartial" };
        // ...
        // Add rows bound to model fields.
        settings.Rows.Add("FirstName");
        settings.Rows.Add("LastName");
        // Add an unbound row.
        settings.Rows.Add(row => {
            // "FieldName" contains a unique value that does not refer to any field in the VerticalGrid's data model. 
            row.FieldName = "FullName";
            // The row contains string values.
            row.UnboundType = DevExpress.Data.UnboundColumnType.String;
            // An unbound expression.
            row.UnboundExpression = "[FirstName]+' '+[LastName]";
        });
    }).Bind(Model).GetHtml()
    
  • Using a Delegate Method

    To provide unbound rows with data using a delegate method, assign this delegate method to the VerticalGridSettings.CustomUnboundRowData property. The delegate method assigned to this property will be called for unbound rows only.

    The code sample below demonstrates how to add an unbound row that retrieves data using a delegate method.

    Partial View code:

    @Html.DevExpress().VerticalGrid(settings => {
        settings.Name = "VerticalGrid";
        settings.CallbackRouteValues = new { Controller = "Home", Action = "VerticalGridPartial" };
        // ...
        // Add rows bound to model fields.
        settings.Rows.Add("FirstName");
        settings.Rows.Add("LastName");
        settings.Rows.Add(row => {
            // "FieldName" contains a unique value that does not refer to any field in the VerticalGrid's data model. 
            row.FieldName = "FullName";
            // The row contains string values.
            row.UnboundType = DevExpress.Data.UnboundColumnType.String;
        });
        // A delegate method that allows you to generate data for an unbound row.
        settings.CustomUnboundRowData = (s, e) => {
            if (e.Row.FieldName == "FullName") {
                string firstName = (e.GetListSourceFieldValue("FirstName")).ToString();
                string lastName = (e.GetListSourceFieldValue("LastName")).ToString();
                e.Value = firstName + " " + lastName;
            };
        };
    }).Bind(Model).GetHtml()
    

Note

When the VerticalGrid extension is bound to a data source in Database Server Mode, you can only enable sorting, filtering and summary calculation for unbound rows that are populated with unbound expressions.