DotVVM DataPager无法正常工作

时间:2017-07-26 06:32:49

标签: dotvvm

带有DataPager的dothtml表:

<bp:GridView DataSource="{value: UserRoleGroupListDTOs}" class="table table-bordered table-hover dataTable">
                <Columns>
                    <%--<dot:GridViewTextColumn ValueBinding="{value: Name}" HeaderText="Název" Events.Click="{command: GoToDetail() }"/>--%>
                    <bp:GridViewTemplateColumn HeaderText="{resource: eCENTRE.Common.Resources.Admin.Common.Name}">
                        <dot:RouteLink Text="{value: Name}" RouteName="UserRoleGroupDetail" Param-Id="{value: Id}" />
                    </bp:GridViewTemplateColumn>
                    <bp:GridViewCheckBoxColumn ValueBinding="{value: IsBlocked}" HeaderText="{resource: eCENTRE.Common.Resources.Admin.Common.Forbidden}" IsEditable="true"/>
                    <bp:GridViewTemplateColumn HeaderText="{resource: eCENTRE.Common.Resources.Admin.Common.Delete}" CssClass="align center">
                        <%--<i class="glyphicon glyphicon-remove remove-from-list" style="color:red;">
                        </i>--%>
                        <dot:Button class="btn btn-default" Click="{command: _parent.DeleteUserRoleGroup(Id)}" Text="{resource: eCENTRE.Common.Resources.Admin.Common.Delete}"/>

                    </bp:GridViewTemplateColumn>
                </Columns>

            </bp:GridView>
            <bp:DataPager DataSet="{value: UserRoleGroupListDTOs}"/>

ViewModel和init in function Prerender:

public GridViewDataSet<UserRoleGroupListDTO> UserRoleGroupListDTOs { get; set; }

    private readonly IUserRoleGroupFacade userRoleGroupDetailFacade;
    private readonly UserRoleGroupCrudFacade crudFacade;

    public UserRoleGroupListViewModel(IUserRoleGroupFacade userRoleGroupDetailFacade, UserRoleGroupCrudFacade crudFacade)
    {
        this.userRoleGroupDetailFacade = userRoleGroupDetailFacade;
        this.crudFacade = crudFacade;
    }

    public override Task Init()
    {
        return base.Init();
    }
    public override Task PreRender()
    {
        UserRoleGroupListDTOs = new GridViewDataSet<UserRoleGroupListDTO>();
        UserRoleGroupListDTOs.PagingOptions.PageSize = 10;
        UserRoleGroupListDTOs.SortingOptions.SortDescending = true;
        UserRoleGroupListDTOs.SortingOptions.SortExpression = nameof(UserRoleGroupListDTO.Name);
        UserRoleGroupListDTOs.OnLoadingData = options => Task.Run(() => userRoleGroupDetailFacade.GetUserRoleGroupGridViewDataSetLoadedData(options)).Result;

        return base.PreRender();
    }

传呼机确实显示,但点击任何按钮后,什么也没发生。

如果我在Init方法中添加初始化,则寻呼机工作,但viewModel有另一个错误。

2 个答案:

答案 0 :(得分:1)

正如Tomas所写,您创建了新的数据集实例,因此丢失了PagingOptions。

您必须仅在新请求中使用init数据集,而不是在回发中。

$

然后你必须在load或PreRender中设置delagate OnLoadingData

public override Task Init()
{
    if (!Context.IsPostBack)
    {
        UserRoleGroupListDTOs = new GridViewDataSet<UserRoleGroupListDTO>
        {
            PagingOptions = { PageSize = 10 },
            SortingOptions =
            {
                SortDescending = true,
                SortExpression = nameof(UserRoleGroupListDTO.Name)
            },
        };
    }
    return base.Init();
}

答案 1 :(得分:0)

您需要在Init阶段初始化寻呼机。 处理完页面命令后发生PreRender事件。您基本上用初始数据集覆盖数据集。

请参阅ViewModels Documentation

中的图表