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

Auto Generate from multilayer Json

4 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Iman
Top achievements
Rank 1
Iman asked on 17 Oct 2018, 03:33 AM

Hi

I have a Class like this : 

public class History
{
public bool Wt_loss { get; set; }
 public bool WT_Gain { get; set; }
 public bool HairLoss { get; set; }
}
 public class PmhDh{
public string Levothyroxine { get; set; }
 }
 public class Datum{
public History History { get; set; }
public PmhDh PmhDh { get; set; }
 }

and i fill the main class with some data

i want to show this class in kendo grid mvc wit main header and sub header but i my code not work correctly

this is my grid code :

@(Html.Kendo().Grid<dynamic>()
                 .Name("gridEQ")
                 .Columns(columns => columns.AutoGenerate(true))
                 .Sortable()
                 .Pageable()
                 .Scrollable()
                 .DataSource(d => d
                     .Ajax()
                     .PageSize(20)
                     .ServerOperation(true)
                     .Read(r => r.Action("SendData", "Thyroid"))
                     
                 ))

and attach the result on this post

please help me

thanks

4 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 18 Oct 2018, 09:13 AM
Hi Iman,

The DataSource widget was designed for showing flat data out of the box. When a complex object is passed to it it should either be flattened or the specific field should be set in the Grid Columns configuration. This is necessary in order for the Grid to know what property from the object should be displayed in the column.

With that said, if the Grid needs to be bound to Datum the columns configuration would look similar to the following:


@(Html.Kendo().Grid<Datum>()
    .Name("gridEQ")
    .Columns(columns =>
    {
        columns.Bound(p => p.History.Wt_loss);
        columns.Bound(p => p.History.WT_Gain);
        columns.Bound(p => p.History.HairLoss);
        columns.Bound(p => p.PmhDh.Levothyroxine);
    }
    )
    .Sortable()
    .Pageable()
    .Scrollable()
    .DataSource(d => d
        .Ajax()
        .PageSize(20)
        .ServerOperation(true)
        .Read(r => r.Action("SendData", "Thyroid"))
      
 ))


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Iman
Top achievements
Rank 1
answered on 19 Oct 2018, 08:13 AM

Thanks for helping

I change my code to this format :

@(Html.Kendo().Grid<TMain>()
                .Name("gridEQ")
                
                .Columns(c =>
                {
 
                    c.Group(g =>
                        g.Title("History")
                            .Columns(i =>
                            {
                                i.Bound(x => x.History.HairLoss);
                                i.Bound(x => x.History.WT_Gain);
                                i.Bound(x => x.History.Wt_loss);
                            })
                        );
                    c.Group(g =>
                        g.Title("PmhDh")
                            .Columns(i =>
                            {
                                i.Bound(x => x.PmhDh.Levothyroxine);
                            })
                        );
 
                })
                .Sortable()
                .Pageable()
                .Scrollable()
                .DataSource(d => d
                    .Ajax()
                    .PageSize(20)
                    .ServerOperation(true)
                    .Read(r => r.Action("SendData", "Thyroid"))
 
                ))

 

and this is my Actionresult : 

01.var result = dbase.Thyroids.ToList();
02.               var mylist = new List<TMain>();
03.               foreach (var item in result)
04.               {
05.                   var tmode = JsonConvert.DeserializeObject<TMain>(item.Value);
06.                   mylist.Add(tmode);
07.                    
08.               }
09. 
10. 
11.               var dsResult = result.ToDataSourceResult(request);
12.               return Json(dsResult);

 

but the grid have no data.

can you help me

0
Iman
Top achievements
Rank 1
answered on 19 Oct 2018, 09:54 AM

I read many post and i see someone has same problem  This Link

and i try change many things but my grid not work correctly . 

i read something that i must set default value but it's not working for me .

so . what must i do ?

0
Viktor Tachev
Telerik team
answered on 23 Oct 2018, 11:16 AM
Hi Iman,

Would you send us a runnable project where the behavior you are seeing is replicated? This will enable us to examine it locally and look for its cause.


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Iman
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Iman
Top achievements
Rank 1
Share this question
or