Gary Kirk
Gary Kirk

Reputation: 1

DotVvm DataPager not paging

I have a GridView which is bound to a GridViewDataSet. The grid displays correctly along with the Pager. When you try to change the page an error is thrown in the background and the page does not change.

View Code

<bs:GridView DataSource="{value: Skus}" class="table table-striped table-bordered">
    <Columns>
        <dot:GridViewTextColumn ValueBinding="{value: RecordType}" HeaderText="Category" />
        <dot:GridViewTextColumn ValueBinding="{value: ContourSku}" HeaderText="Contour SKU" />
        <dot:GridViewTextColumn ValueBinding="{value: ProductName}" HeaderText="Product Name" />
        <dot:GridViewTextColumn ValueBinding="{value: CdsCost}" FormatString="c" HeaderText="CDS Cost" />
        <dot:GridViewTextColumn ValueBinding="{value: ListPrice}" FormatString="c" HeaderText="List Price" />
        <dot:GridViewTextColumn ValueBinding="{value: ExtendedMrc}" FormatString="c" HeaderText="MRC" />

        <dot:GridViewTemplateColumn HeaderText="Active" AllowSorting="false">
            <ContentTemplate>
                <bp:SwitchButton Text="" Checked="{value: IsActive}">
                </bp:SwitchButton>
            </ContentTemplate>
        </dot:GridViewTemplateColumn>
    </Columns>
</bs:GridView>

<bs:DataPager DataSet="{value: Skus}" />

**ViewModel**
    [Bind(Direction.ServerToClient)]
    public GridViewDataSet<CloudProductEntity> Skus { get; set; } 

    public override Task Init()
    {
        if (!Context.IsPostBack)
        {
            Skus = new GridViewDataSet<CloudProductEntity>
            {
                PagingOptions = { PageSize = 10 },
                SortingOptions =
                {
                    SortDescending = true,
                    SortExpression = nameof(CloudProductEntity.ContourSku)
                },
            };
            Skus.LoadFromQueryable(CloudProductEntity.Search(Search).AsQueryable());
        }
        return base.Init();
    }

Upvotes: 0

Views: 109

Answers (1)

Tom&#225;š Herceg
Tom&#225;š Herceg

Reputation: 1640

There are two problems that prevent the paging from working correctly:

  1. Unfortunately, GridViewDataSet doesn't support one-way bind directions as the paging and sorting parameters are stored in it and need to be submitted to the server.

  2. Init is not a good place to load data from the database - the recommended way is PreRender which happens after postback commands. Also, it is better to check whether DataSet.IsRefreshRequired than checking on Context.IsPostBack, as there may be postbacks that don't require to reload the data.

Upvotes: 0

Related Questions