Skip to main content

DataView

  • 2 minutes to read

The DataView is an extremely flexible tool for data presentation on the web. Its main purpose is to arrange data record placeholders and provide navigation between them. Record content is then fully customizable via templates.

To learn more about the DataView and see it in action, refer to its online demos.

Implementation Details

The DataView is realized by the DataViewExtension class. Its instance can be accessed via the ExtensionsFactory.DataView helper method, which is used to add a DataView extension to a view. This method’s parameter provides access to the DataView‘s settings implemented by the DataViewSettings class, allowing you to fully customize the extension.

The DataView‘s client counterpart is represented by the MVCxClientDataView object.

Declaration

The DataView can be added to a view in the following manner.

View code (Razor):

@Html.DevExpress().DataView(
    settings => {
        settings.Name = "dataView";
        settings.CallbackRouteValues = new { Controller = "DataView", Action = "DataBindingPartial" };
        settings.SettingsTableLayout.RowsPerPage = 2;
        settings.Width = Unit.Percentage(100);
        settings.PagerAlign = PagerAlign.Justify;
        settings.SetItemTemplateContent(
            c => {
                ViewContext.Writer.Write(
                    "<table>" +
                        "<tr>" +
                            "<td colspan=\"2\">" +
                                "<img src=\"" + Url.Content(DataBinder.Eval(c.DataItem, "PhotoUrl").ToString()) + "\" alt=\"\" />" +
                            "</td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><b>Name:</b></td>" +
                            "<td><span>" + DataBinder.Eval(c.DataItem, "Name") + "</span></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><b>Address:</b></td>" +
                            "<td><span>" + DataBinder.Eval(c.DataItem, "Address") + "</span></td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td><b>Phone:</b></td>" +
                            "<td><span>" + DataBinder.Eval(c.DataItem, "Phone") + "</span></td>" +
                        "</tr>" +
                    "</table>"
                );
            }
        );
        settings.PagerSettings.ShowNumericButtons = true;
        settings.PagerSettings.AllButton.Visible = false;
        settings.PagerSettings.Summary.Visible = false;
        settings.PagerSettings.PageSizeItemSettings.Visible = true;
        settings.PagerSettings.PageSizeItemSettings.ShowAllItem = true;
    }
).BindToXML(HttpContext.Current.Server.MapPath("~/App_Data/Contacts.xml"), "//Contact").GetHtml()

Note

The Partial View should contain only the extension’s code.

The result is demonstrated in the image below.

DataViewItem