This is a migrated thread and some comments may be shown as answers.

Error while bind grid column dynamically

10 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cygnet
Top achievements
Rank 1
Cygnet asked on 08 Feb 2021, 11:22 AM

We bind Kendo Grid column dynamically from DB in .net MVC.While we bind that column in Kendo Grid it will give me an error in Browser Console like

"Uncaught SyntaxError: Unexpected identifier".

I have also attached screen shot for console Error and my Code to bind Kendo Grid.

10 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 10 Feb 2021, 09:44 AM

Hi,

 

Thank you for writing to us.

I've gone through the provided snapshots and it seems that the issue is most probably related to one of the following:

1. Format()

2. FooterTemplate or any other template

3. Other javascript error.

So my suggestion as the next step would be to remove or comment out all grid columns temporarily and run the web page again to verify that the problem is related to the column definitions.

Also run the web site on Chrome and always keep the F12 inspector console opened.

Fee free to give this a try and let me know about the result.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Cygnet
Top achievements
Rank 1
answered on 15 Feb 2021, 06:39 AM

As per you suggestion i did try to comment the column code and run in the chrome then also give it same error in console

I think this is due to DataTable binding with the Grid.

So can you please suggest anything which we adding into it and resolve the Console error

Thanks.

0
Eyup
Telerik team
answered on 16 Feb 2021, 10:29 AM

Hi Cygnet,

 

I am sending a working MVC sample with dynamic columns. It is located in:
Views/Grid/ComboInHeader.cshtml

Feel free to run the page and verify that it is working as expected and there are no errors in the console. Then, you can simulate your own grid to replicate the issue you are having and send the modified version back to us. This will allow us to reproduce the problem locally and provide more accurate and precise suggestions to resolve it.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Cygnet
Top achievements
Rank 1
answered on 17 Feb 2021, 09:23 AM

Hi

I am sending you full source with the created view has name "ColumnBind.cshtml" and controller method in "EditingController.cs" has Fix value.

You can run this view and it has same error in console which we are facing.

Thanks

 

0
Cygnet
Top achievements
Rank 1
answered on 17 Feb 2021, 10:15 AM

Hi

There is some error while attaching full source

I attached here files and mention the folder name.Please put those file in the folder and just run you can find same error

Please put  "ColumnBind.cshtml" in the Views\Grid folder

Replace EditingController.cs, ProductViewModel.cs file

 

Thanks

0
Eyup
Telerik team
answered on 19 Feb 2021, 09:15 AM

Hi,

 

Thank you for the provided code files.

I am now able to reproduce the issue and will check which column exactly causes the problem.

Thank you for your patience in advance. I will get back to you with my findings next week.

 

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Eyup
Telerik team
answered on 22 Feb 2021, 07:16 AM

Hello,

 

I went through the provided sample thoroughly and here is what I found out:

You need also to declare the .Read() action of the grid's datasource in order to complete the binding:

.Read(read => read.Action("Read", "Home"))
And the Controller method needs to return JSON which can be interpreted by the grid:
        public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
            DataTable products = Products();
            
            if (request.Aggregates.Any())
            {
                request.Aggregates.Each(agg =>
                    {
                        agg.Aggregates.Each(a =>
                            {
                                a.MemberType = products.Columns[agg.Member].DataType;
                            });
                    });
            }

            return Json(products.ToDataSourceResult(request));
        }
The sample which refers to this sample is located here:
https://docs.telerik.com/aspnet-mvc/html-helpers/data-management/grid/how-to/Binding/grid-bind-to-datatable 

And this is the full sample:
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/binding-to-datatable

And here is another (older) one:
https://www.telerik.com/support/code-library/binding-to-datatable-0191a594e359

I hope the provided working projects and references will prove a nice stepping stone and help you achieve the full implementation.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Cygnet
Top achievements
Rank 1
answered on 25 Feb 2021, 01:23 PM

Hello

Can you please refer my code which i already added in the controller and view because this solution is not worked for me.In my case it has more than one list and from that List i need to bind individual column in datatable.

Can you please just verify this code and suggest me solution which i attach below.

0
Cygnet
Top achievements
Rank 1
answered on 25 Feb 2021, 01:24 PM
Controller and View files 
0
Eyup
Telerik team
answered on 01 Mar 2021, 11:58 AM

Hello,

 

Can you send me the full sample in an isolated runnable format without any dependencies?

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Cygnet
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Cygnet
Top achievements
Rank 1
Share this question
or