We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to dinamycally create grid columns?

Thread ID:

Created:

Updated:

Platform:

Replies:

148280 Oct 13,2019 06:07 PM UTC Oct 15,2019 05:12 AM UTC Blazor 3
loading
Tags: Grid
Emilio
Asked On October 14, 2019 09:09 AM UTC

Hi, 

using 17.3.17.

I've tried this to create grid columns dinamically.


@page "/gridDinamyc"

   

@code{
    EjsGrid grid;
    protected override void OnAfterRender()
    {
        List col = new List();
        col.Add(new GridColumn() { Field = "OrderID", HeaderText = "ID" });
        col.Add(new GridColumn() { Field = "CustomerID", HeaderText = "Name" });
        grid.Columns = col;
        var dataManager = new EjsDataManager();
        dataManager.CrossDomain = true;
        dataManager.Adaptor = Adaptors.WebApiAdaptor;
        dataManager.EnableCaching = false;
        dataManager.Url = "https://ej2services.syncfusion.com/production/web-services/api/Orders";
        dataManager.Offline = false;
        grid.DataSource = dataManager;    
    }

But compiler throw errors

error CS0115: 'GridDinamyc.OnAfterRender()': no suitable method found to override
error CS0305:Using the generic type EjsGridrequires 1 type arguments


Renjith Singh Rajendran [Syncfusion]
Replied On October 14, 2019 12:06 PM UTC

Hi Emilio, 

Query 1 : error CS0115: 'GridDinamyc.OnAfterRender()': no suitable method found to override 
We suggest you to pass the argument for the “OnAfterRender()” method to overcome this error. This is a default lifecycle method from blazor. And they have modified this lifecycle methods in their latest version to be used along with argument. Please refer the code below, 

 
    protected override void OnAfterRender(bool isrender) 
    { 
        ... 
   } 

 
Query 2 : error CS0305:Using the generic type 'generic type' EjsGrid<TValue>' requires 'number' type arguments 
We have provided Generic type support for our Syncfusion controls in our previous version 17.2.40, so all the versions following this will support generic type. As you are using our latest version(17.3.17), kindly refer the below release notes for your reference and do the necessary changes in your application. 

Please use the code below, 
 
<EjsGrid @ref=@grid TValue="Order" AllowPaging="true" Width="100%" Height="100%"> 
    ... 
</EjsGrid> 
 
@code{ 
   EjsGrid<Order> grid; 
    ... 
} 


As like your code, you cannot directly assign the EjsDataManager to the DataSource property of EjsGrid. If you want to enable EjsDataManager in Grid after initial rendering then we suggest you to refer to the below documentation for more details regarding this, 

We have also prepared a sample by modifying your codes, in which we have added the above mentioned suggestions and enabled the EjsDataManager by using the “OnDataBound” event of Grid. Please download the sample from the link below, 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Emilio
Replied On October 14, 2019 06:46 PM UTC

Thank you for the working sample!



Renjith Singh Rajendran [Syncfusion]
Replied On October 15, 2019 05:12 AM UTC

Hi Emilio, 

Thanks for your update. 

We are glad to hear that our sample helped you in achieving your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon