formsblazorteleriktelerik-grid

How to Nest a TelerikGrid inside TelerikForm with Blazor


I have a TelerikForm with FormItems --> FormGroup --> FormItem(s) and I am wanting to have in the middle or bottom of my form to have a Grid in which I can add new items with multiple rows.

I was adding in TelerikGrid with GridColumns and it renders but puts the grid at the top of the page. It has been a while since I used Telerik, so I'm wondering how I can have the nice form , with the nice looking grid inside of it without too much css manipulation.

There is a blazor repl that I'm using as a playground.
https://blazorrepl.telerik.com/wSkHQXwH29FwQkMD29

<TelerikForm Model="@TestUser"
                     Width="700px"
                     Columns="2"
                     ColumnSpacing="20px"
                     OnValidSubmit="@HandleValidSubmit"
                     OnInvalidSubmit="@HandleInvalidSubmit">
            <FormValidation>
                <DataAnnotationsValidator></DataAnnotationsValidator>
            </FormValidation>
            <FormItems>
                <FormGroup LabelText="User Information">
            ...................
             <TelerikGrid Data="@items" TItem=GridItem AutoGenerateColumns="false">
               <GridColumns>
                  <GridColumn Field="@nameof(GridItem.Name)" Title="Name" />
                  <GridColumn Field="@nameof(GridItem.Value)" Title="Value" />
              </GridColumns>
             </TelerikGrid>

            </FormItems>
            
/TelerikForm>


Solution

  • You can provide a custom layout that allows this

    First, I added an empty FormGroup that will render the TelerikGrid.

    Then supply a FormItemsTemplate

    <FormItemsTemplate Context="formContext">
        @{
            //formContext.Items contains all FormItems and FormGroups at root level
            var formObjects = formContext.Items;
        }
        <TelerikFormGroupRenderer Group="@( (IFormGroup)formObjects[0] )">
        </TelerikFormGroupRenderer>
        <TelerikFormGroupRenderer Group="@( (IFormGroup)formObjects[2] )">
            <Template>
            <TelerikGrid Data="@items" TItem=GridItem AutoGenerateColumns="false">
                <GridColumns>
                    <GridColumn Field="@nameof(GridItem.Name)" Title="Name" />
                    <GridColumn Field="@nameof(GridItem.Value)" Title="Value" />
                </GridColumns>
            </TelerikGrid>
            </Template>
        </TelerikFormGroupRenderer>
        <TelerikFormGroupRenderer Group="@( (IFormGroup)formObjects[1] )">
        </TelerikFormGroupRenderer>
    </FormItemsTemplate>            
    

    REPL: https://blazorrepl.telerik.com/myayOzEi598Vuqj722