Skip to main content

Data Paging

  • 4 minutes to read

This topic describes the concept of data paging, including an overview of the paging functionality, appearance customization, as well as how to navigate pages on the server and client sides.

Data Paging Overview

By default, the VerticalGrid automatically splits content across multiple pages and provides end-users with an embedded page navigation UI - Pager.

MVC_VerticalGrid_PagerItems

The built-in pager enables end-users to navigate through VerticalGrid data. It consists of the following navigation buttons: Next, Last, Previous, First and All. It also includes an indicator that displays the current page number and the total number of pages, and a page size item allowing you to specify the maximum number of rows that can be displayed within a page. To access and customize pager settings, use the VerticalGridSettings.SettingsPager property.

To disable page navigation and display all rows within the grid, set the ASPxVerticalGridPagerSettings.Mode (through VerticalGridSettings.SettingsPager.Mode) property to VerticalGridPagerMode.ShowAllRecords.

Appearance Customization

The pager can be displayed above or below the rows, or on both sides. Use the ASPxGridPagerSettings.Position (through VerticalGridSettings.SettingsPager.Position) property to specify the pager’s position within the VerticalGrid.

MVC_VerticalGrid_Paging_TopBoth

The maximum number of rows that can be displayed within a page can be accessed using the ASPxVerticalGridPagerSettings.PageSize (using VerticalGridSettings.SettingsPager.PageSize) property.

The VerticalGrid‘s look and feel can be customized with Templates. A template is a set of HTML elements and ASP.NET MVC extensions that define the layout for a particular element within the ASP.NET MVC extension (e.g., a pager). When the extension runs in the web page, template content is rendered in place of the default HTML for the extension.

Example

The code sample below demonstrates how to implement a custom pager using templates.

Partial View code:

@Html.DevExpress().VerticalGrid(settings => {
    settings.Name = "VerticalGrid";
    // ...
    settings.SetPagerBarContent(c => {
        // Render Prev button 
        ViewContext.Writer.Write("<div style=\"float:left;padding-right:20px;\">");
        Html.DevExpress().Button(s => {
            s.Name = "prevPage";
            s.Images.Image.IconID = IconID.ArrowsPrev32x32;
            s.RenderMode = ButtonRenderMode.Link;
            s.Text = String.Empty;
            s.ClientSideEvents.Click = @"function (s, e) { VerticalGrid.PrevPage(); }";
        }).Render();
        ViewContext.Writer.Write("</div>");
        // Render custom summary 
        ViewContext.Writer.Write("<div style=\" float:left; padding-top:6px; \">");
        Html.DevExpress().Label(s => {
            s.Name = "currentPage";
            s.Properties.ClientSideEvents.Init = @"function (s, e) { 
                var text = 'Page ' + (VerticalGrid.GetPageIndex() +1) + '/' + VerticalGrid.GetPageCount(); 
                s.SetText(text); 
            }";
        }).Render();
        ViewContext.Writer.Write("</div>");
        // Render Next button 
        ViewContext.Writer.Write("<div style=\" float:left; padding-left:20px; \">");
        Html.DevExpress().Button(s => {
            s.Name = "nextPage";
            s.Images.Image.IconID = IconID.ArrowsNext32x32;
            s.RenderMode = ButtonRenderMode.Link;
            s.Text = String.Empty;
            s.ClientSideEvents.Click = @"function (s, e) { VerticalGrid.NextPage(); }";
        }).Render();
        ViewContext.Writer.Write("</div>");
    });
}).Bind(Model).GetHtml()

The image below illustrates the result.

MVC_VerticalGrid_Paging_CustomPager

Page Navigation on the Server Side

The active page is determined by the ASPxGridBase.PageIndex (through MVCxVerticalGrid.PageIndex) property. Use this property to switch between pages in code. The total number of pages can be obtained using the ASPxGridBase.PageCount (through MVCxVerticalGrid.PageCount) property.

Example

The code sample below demonstrates how to define the initially displayed page on the first start.

Partial View code:

@Html.DevExpress().VerticalGrid(settings =>
{
    settings.Name = "VerticalGrid";
    // ...
    settings.SettingsPager.PageSize = 3;

    settings.PreRender = (s, e) =>
    {
        var sender = s as MVCxVerticalGrid;
        // Set the zero-based index of the initially displayed page
        sender.PageIndex = 1;
    };
}).Bind(Model).GetHtml()

The image below illustrates the result.

MVC_VerticalGrid_PageIndexExample

Page Navigation on the Client Side

The VerticalGrid provides a client-side API that enables you to navigate a user to a specific page. The table below lists the available navigation-related methods.

Method Description
ASPxClientVerticalGrid.GotoPage Selects the specified page.
ASPxClientVerticalGrid.NextPage Activates the next page.
ASPxClientVerticalGrid.PrevPage Activates the previous page.

Example

The example below demonstrates how to enable an end-user to navigate to any VerticalGrid page without clicking the pager. In this example, an end-user can use the SpinEdit editor to specify (by entering the number manually or by clicking the spin buttons) the page number to which the grid should be paged.

View Code:

<script type="text/javascript">
    function OnValueChanged(s, e) {
        VerticalGrid.GotoPage(s.GetValue()-1);
    }
</script>

@Html.Action("VerticalGridPartial")
<br />
<div style="float:left; padding-right:5px;">Go to page:</div>
<div style="float:left">
@Html.DevExpress().SpinEdit(settings => {
    settings.Name = "SpinEdit";
    settings.Properties.ClientSideEvents.ValueChanged = "OnValueChanged";
}).GetHtml()
</div>

Partial View code:

@Html.DevExpress().VerticalGrid(settings =>
{
    settings.Name = "VerticalGrid";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "VerticalGridPartial" };

    settings.KeyFieldName = "CustomerID";
    settings.Rows.Add("ContactName");
    settings.Rows.Add("CompanyName");
    settings.Rows.Add("City");
    settings.Rows.Add("Region");
    settings.Rows.Add("Country");
    // ...
    settings.SettingsPager.PageSize = 5;
}).Bind(Model).GetHtml()

The image below illustrates the result.

MVC_VerticalGrid_PageIndexExampleClient