DataPager

in namespace DotVVM.Bootstrap5.Controls

Extends the built-in DataPager control with Bootstrap CSS classes.

Usage & Scenarios

Extends the builtin DataPager control to set up Bootstrap look of the control.

https://getbootstrap.com/docs/5.2/components/pagination/

Sample 1: DataPager Sizing

Use the Size property to set the size of the pager.

<bs:GridView DataSource="{value: Customers}">
  <Columns>
    <dot:GridViewTextColumn ValueBinding="{value: Id}" HeaderText="ID" />
    <dot:GridViewTextColumn ValueBinding="{value: Name}" HeaderText="Name" />
  </Columns>
</bs:GridView>

<bs:DataPager Size="Default" DataSet="{value: Customers}" />
<bs:DataPager Size="Small" DataSet="{value: Customers}" />
<bs:DataPager Size="Large" DataSet="{value: Customers}" />
using System;
using System.Linq;
using System.Threading.Tasks;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DataPager.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        private static IQueryable<Customer> FakeDb()
        {
            return new[]
            {
                new Customer(0, "Dani Michele"), new Customer(1, "Elissa Malone"), new Customer(2, "Raine Damian"),
                new Customer(3, "Gerrard Petra"), new Customer(4, "Clement Ernie"), new Customer(5, "Rod Fred"),
                new Customer(6, "Oliver Carr"), new Customer(7, "Jackson James"), new Customer(8, "Dexter Nicholson"),
                new Customer(9, "Jamie Rees"), new Customer(10, "Jackson Ross"), new Customer(11, "Alonso Sims"),
                new Customer(12, "Zander Britt"), new Customer(13, "Isaias Ford"), new Customer(14, "Braden Huffman"),
                new Customer(15, "Frederick Simpson"), new Customer(16, "Charlie Andrews"), new Customer(17, "Reuben Byrne")
            }.AsQueryable();
        }

        public GridViewDataSet<Customer> Customers { get; set; } = new GridViewDataSet<Customer>() { PagingOptions = { PageSize = 4} };

        public override Task PreRender()
        {
            if (Customers.IsRefreshRequired)
            {
                var queryable = FakeDb();
                Customers.LoadFromQueryable(queryable);
            }
            return base.PreRender();
        }

    }


    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Customer()
        {
            // NOTE: This default constructor is required. 
            // Remember that the viewmodel is JSON-serialized
            // which requires all objects to have a public 
            // parameterless constructor
        }

        public Customer(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }
}

Sample 2: Hide datapager if has only one page

By default, property HideWhenOnlyOnePage is set true, but if you want to hide datapager, while has only one page, set this property to false.

<bs:GridView DataSource="{value: Customers}">
  <Columns>
    <dot:GridViewTextColumn ValueBinding="{value: Id}" HeaderText="ID" />
    <dot:GridViewTextColumn ValueBinding="{value: Name}" HeaderText="Name" />
  </Columns>
</bs:GridView>

<bs:DataPager HideWhenOnlyOnePage="true" DataSet="{value: Customers}" />
<bs:DataPager HideWhenOnlyOnePage="false" DataSet="{value: Customers}" />
using System;
using System.Linq;
using System.Threading.Tasks;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DataPager.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        private static IQueryable<Customer> FakeDb()
        {
            return new[]
            {
                new Customer(0, "Dani Michele"), new Customer(1, "Elissa Malone"), new Customer(2, "Raine Damian")
            }.AsQueryable();
        }

        public GridViewDataSet<Customer> Customers { get; set; } = new GridViewDataSet<Customer>() { PagingOptions = { PageSize = 4} };

        public override Task PreRender()
        {
            if (Customers.IsRefreshRequired)
            {
                var queryable = FakeDb();
                Customers.LoadFromQueryable(queryable);
            }
            return base.PreRender();
        }

    }


    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Customer()
        {
            // NOTE: This default constructor is required. 
            // Remember that the viewmodel is JSON-serialized
            // which requires all objects to have a public 
            // parameterless constructor
        }

        public Customer(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }
}

Sample 3: Page Templates

If you want to change appearance of Datapager buttons use property FirstPageTemplate, NextPageTemplate, PrevoiousPageTemplate and LastPageTemplate.

<bs:GridView DataSource="{value: Customers}">
  <Columns>
    <dot:GridViewTextColumn ValueBinding="{value: Id}" HeaderText="ID" />
    <dot:GridViewTextColumn ValueBinding="{value: Name}" HeaderText="Name" />
  </Columns>
</bs:GridView>

<bs:DataPager DataSet="{value: Customers}">
  <FirstPageTemplate>First</FirstPageTemplate>
  <LastPageTemplate>Last</LastPageTemplate>
  <NextPageTemplate>Next</NextPageTemplate>
  <PreviousPageTemplate>Previous</PreviousPageTemplate>
</bs:DataPager>
using System;
using System.Linq;
using System.Threading.Tasks;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DataPager.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        private static IQueryable<Customer> FakeDb()
        {
            return new[]
            {
                new Customer(0, "Dani Michele"), new Customer(1, "Elissa Malone"), new Customer(2, "Raine Damian"),
                new Customer(3, "Gerrard Petra"), new Customer(4, "Clement Ernie"), new Customer(5, "Rod Fred"),
                new Customer(6, "Oliver Carr"), new Customer(7, "Jackson James"), new Customer(8, "Dexter Nicholson"),
                new Customer(9, "Jamie Rees"), new Customer(10, "Jackson Ross"), new Customer(11, "Alonso Sims"),
                new Customer(12, "Zander Britt"), new Customer(13, "Isaias Ford"), new Customer(14, "Braden Huffman"),
                new Customer(15, "Frederick Simpson"), new Customer(16, "Charlie Andrews"), new Customer(17, "Reuben Byrne")
            }.AsQueryable();
        }

        public GridViewDataSet<Customer> Customers { get; set; } = new GridViewDataSet<Customer>() { PagingOptions = { PageSize = 4} };

        public override Task PreRender()
        {
            if (Customers.IsRefreshRequired)
            {
                var queryable = FakeDb();
                Customers.LoadFromQueryable(queryable);
            }
            return base.PreRender();
        }

    }


    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Customer()
        {
            // NOTE: This default constructor is required. 
            // Remember that the viewmodel is JSON-serialized
            // which requires all objects to have a public 
            // parameterless constructor
        }

        public Customer(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }
}

Sample 4: Justify content (Horizontal Alignment)

Use JustifyContentAll property on flexbox containers to change the alignment of flex items on the main axis for all screen sizes.

There are also JustifyContentSmall, JustifyContentMedium, JustifyContentLarge, JustifyContentXLarge and JustifyContentXXLarge to specify the behavior for particular screen sizes.

  • None aligns the columns by defaultt.
  • Start aligns the columns to the left.
  • Center aligns the columns to the middle.
  • End aligns the columns to the right.
  • Around distributes the remaining space equally in the gaps between columns. Items have a half-size space on either end.
  • Between distributes the remaining space equally in the gaps between columns. The first item is flush with the start, the last is flush with the end.
  • Evenly distributes the remaining space equally in the gaps between columns. Items have equal space around them.

See the diagram in Bootstrap Grid documentation.

<bs:GridView DataSource="{value: Customers}">
  <Columns>
    <dot:GridViewTextColumn ValueBinding="{value: Id}" HeaderText="ID" />
    <dot:GridViewTextColumn ValueBinding="{value: Name}" HeaderText="Name" />
  </Columns>
</bs:GridView>

<bs:DataPager DataSet="{value: Customers}" JustifyContentAll="Center" />
<bs:DataPager DataSet="{value: Customers}" JustifyContentXLarge="Start" JustifyContentMedium="Evenly"/>
using System;
using System.Linq;
using System.Threading.Tasks;
using DotVVM.Framework.Controls;
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.DataPager.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        private static IQueryable<Customer> FakeDb()
        {
            return new[]
            {
                new Customer(0, "Dani Michele"), new Customer(1, "Elissa Malone"), new Customer(2, "Raine Damian"),
                new Customer(3, "Gerrard Petra"), new Customer(4, "Clement Ernie"), new Customer(5, "Rod Fred"),
                new Customer(6, "Oliver Carr"), new Customer(7, "Jackson James"), new Customer(8, "Dexter Nicholson"),
                new Customer(9, "Jamie Rees"), new Customer(10, "Jackson Ross"), new Customer(11, "Alonso Sims"),
                new Customer(12, "Zander Britt"), new Customer(13, "Isaias Ford"), new Customer(14, "Braden Huffman"),
                new Customer(15, "Frederick Simpson"), new Customer(16, "Charlie Andrews"), new Customer(17, "Reuben Byrne")
            }.AsQueryable();
        }

        public GridViewDataSet<Customer> Customers { get; set; } = new GridViewDataSet<Customer>() { PagingOptions = { PageSize = 4 } };

        public override Task PreRender()
        {
            if (Customers.IsRefreshRequired)
            {
                var queryable = FakeDb();
                Customers.LoadFromQueryable(queryable);
            }
            return base.PreRender();
        }

    }


    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }

        public Customer()
        {
            // NOTE: This default constructor is required. 
            // Remember that the viewmodel is JSON-serialized
            // which requires all objects to have a public 
            // parameterless constructor
        }

        public Customer(int id, string name)
        {
            Id = id;
            Name = name;
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon DataSet IValueBinding<IPageableGridViewDataSet> Gets or sets the GridViewDataSet object in the viewmodel.
attribute
inner element
static value
bindable
default
null
property icon Enabled Boolean Gets or sets whether data pager is enabled.
attribute
inner element
static value
bindable
default
True
property icon FirstPageTemplate ITemplate Gets or sets the template of the button which moves the user to the first page.
attribute
inner element
static value
bindable
default
null
property icon HideWhenOnlyOnePage Boolean Gets or sets whether the pager should hide automatically when there is only one page of results. Must not be set to true when using the Visible property.
attribute
inner element
static value
bindable
default
True
property icon JustifyContentAll BootstrapJustifyContent Gets or sets the flexbox utility CSS class for all screens.
attribute
inner element
static value
bindable
default
null
property icon JustifyContentLarge BootstrapJustifyContent Gets or sets the flexbox utility CSS class for a large screen.
attribute
inner element
static value
bindable
default
null
property icon JustifyContentMedium BootstrapJustifyContent Gets or sets the flexbox utility CSS class for a medium screen.
attribute
inner element
static value
bindable
default
null
property icon JustifyContentSmall BootstrapJustifyContent Gets or sets the flexbox utility CSS class for a small screen.
attribute
inner element
static value
bindable
default
null
property icon JustifyContentXLarge BootstrapJustifyContent Gets or sets the flexbox utility CSS class for a very large screen.
attribute
inner element
static value
bindable
default
null
property icon JustifyContentXXLarge BootstrapJustifyContent Gets or sets the flexbox utility CSS class for the largest screen.
attribute
inner element
static value
bindable
default
null
property icon LastPageTemplate ITemplate Gets or sets the template of the button which moves the user to the last page.
attribute
inner element
static value
bindable
default
null
property icon NextPageTemplate ITemplate Gets or sets the template of the button which moves the user to the next page.
attribute
inner element
static value
bindable
default
null
property icon PreviousPageTemplate ITemplate Gets or sets the template of the button which moves the user to the previous page.
attribute
inner element
static value
bindable
default
null
property icon Size Size Gets or sets the size of the data pager.
attribute
inner element
static value
bindable
default
Default
property icon Visible Boolean Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control.
attribute
inner element
static value
bindable
default
True

HTML produced by the control