Pending Review
Last Updated: 27 Feb 2020 12:39 by ADMIN
Lee
Created on: 19 Feb 2020 11:50
Category: Grid
Type: Feature Request
0
Generate RadGrid schema from client data source
Can the RadGrid generate columns from the client data source schema, it's painful having to manually declare the columns both in the RadGrid and the schema, again can something be done to make this control more user friendly?
5 comments
ADMIN
Peter Milchev
Posted on: 27 Feb 2020 12:39

Hello Lee,

The Grid needs the Columns declared on the server-side. This is where the main difference between the SqlDataSource and ClientDataSource comes into play. 

The SqlDataSource is a server-side control that allows the Grid to get the data and based on it to generate its columns. 

The ClientDataSource is client-side focused control and more often it is configured with client-side data, which is not convenient for the Grid. 

Also, the ClientDataSource allows manipulation of returned data and schema on the client-side, so the Schema is not always a reliable source for autogenerating the columns.

Let me know if there is anything still left unclear.

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Lee
Posted on: 26 Feb 2020 10:55

Hi Peter

 

Yes that works, but I'm wondering if we can have it out of the box to speed up development.  Currently the ClientDataSource integration isn't as slick as the regular SqlDataSource integration (which is spot on by the way, it automatically generates the declaritive column definitions from the datasource control)

 

It would be great if the ClientDataSource could be as easy to integrate.  

 

Cheers

 

Lee

ADMIN
Peter Milchev
Posted on: 26 Feb 2020 10:44

Hello Lee,

Are you after the opposite generation, from the GridColumns to create the Schema Model?

<Schema>
    <Model ID="CustomerID">
        <%--<telerik:ClientDataSourceModelField FieldName="CustomerID" DataType="Number" />
        <telerik:ClientDataSourceModelField FieldName="CompanyName" DataType="String" />
        <telerik:ClientDataSourceModelField FieldName="ContactName" DataType="String" />
        <telerik:ClientDataSourceModelField FieldName="ContactTitle" DataType="String" />--%>
    </Model>
</Schema>

protected void RadClientDataSource1_Init(object sender, EventArgs e)
{
    var clientDataSource = sender as RadClientDataSource;
    foreach (GridColumn col in RadGrid1.Columns)
    {
        if (col is GridBoundColumn)
        {
            clientDataSource.Schema.Model.Fields.Add(new ClientDataSourceModelField() { FieldName = (col as GridBoundColumn).DataField });
        }
    }

}

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
Lee
Posted on: 26 Feb 2020 09:52

Hi Peter 

This isn't quite what i'm after. 

Currently, if you attach a RadGrid to a regular DataSource Control you can generate the columns markup in ASPX.

This is useful as it means I can then quickly adjust the DataFormatString, column type etc in the ASPX, not the codebehind.

It would be great if this could be done with the clientdatasource as well

Cheers

Lee

ADMIN
Peter Milchev
Posted on: 26 Feb 2020 09:34

Hello Lee,

The programmatic generation of the columns can be easily achieved in the Init event of the RadGrid, based on the model fields of the ClientDataSource:

protected void RadGrid1_Init(object sender, EventArgs e)
{
    var grid = sender as RadGrid;
    foreach (ClientDataSourceModelField item in RadClientDataSource1.Schema.Model.Fields)
    {
        grid.Columns.Add(new GridBoundColumn()
        { 
            HeaderText = item.FieldName,
            DataField = item.FieldName
        });
    }
}

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.