protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            var rendererTreeBuilder = new BlazorRendererTreeBuilder(builder);
            var gridContexts        = RendererContextFactory.CreateContexts(tableDataSet);

            RenderFragment <ImutableGridRendererContext> grid = (ImutableGridRendererContext imutableGridRendererContext)
                                                                => delegate(RenderTreeBuilder internalBuilder)
            {
                var gridRendererContext = new GridRendererContext(gridContexts.ImutableRendererContext,
                                                                  new BlazorRendererTreeBuilder(internalBuilder),
                                                                  tableDataSet);
                GridRendererTreeBuilder.BuildRendererTree(gridRendererContext, gridContexts.PermissionContext);
            };

            rendererTreeBuilder
            .OpenComponent(typeof(GridViewTable))
            .AddAttribute(nameof(ImutableGridRendererContext), gridContexts.ImutableRendererContext)
            .AddAttribute(RenderTreeBuilder.ChildContent, grid)
            .CloseComponent();

            if (gridContexts.ImutableRendererContext.CreateItemIsAllowed())
            {
                rendererTreeBuilder
                .OpenComponent(typeof(CreateItemModal))
                .AddAttribute(nameof(CreateItemOptions), gridContexts.ImutableRendererContext.GridConfiguration.CreateItemOptions)
                .AddAttribute(nameof(PermissionContext), gridContexts.PermissionContext)
                .AddAttribute(nameof(CreateFormCssClasses), gridContexts.ImutableRendererContext.CssClasses.CreateFormCssClasses)
                .AddAttribute(nameof(NewItemCreated), NewItemCreated)
                .CloseComponent();
            }
        }
Exemple #2
0
        public void BuildRendererTree(
            IFormLayout <TModel> createFormLayout,
            CreateItemRendererContext <TModel> createItemRendererContext,
            IRendererTreeBuilder rendererTreeBuilder)
        {
            var bodyAction   = createFormLayout.BuildBodyRendererTree(createItemRendererContext, formInputRendererTreeProvider);
            var footerAction = createFormLayout.BuildFooterRendererTree(createItemRendererContext);

            RenderFragment <EditContext> formBody = (EditContext context) => delegate(RenderTreeBuilder builder)
            {
                var internalBuilder = new BlazorRendererTreeBuilder(builder);
                bodyAction?.Invoke(internalBuilder);
                footerAction?.Invoke(internalBuilder);

                internalBuilder
                .OpenComponent(typeof(DataAnnotationsValidator))
                .CloseComponent();
            };

            rendererTreeBuilder
            .OpenComponent(typeof(EditForm))
            .AddAttribute(nameof(EditContext), createItemRendererContext.ViewModel.EditContext)
            .AddAttribute("OnValidSubmit", eventCallbackFactory.Create <EditContext>(this,
                                                                                     context => createItemRendererContext.ViewModel.SaveAction.Invoke(createItemRendererContext.ViewModel.Model)))
            .AddAttribute(RenderTreeBuilder.ChildContent, formBody)
            .CloseComponent();

            createItemRendererContext.ViewModel.ValidateModel();
        }