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

MVC Gird Master/Detail - How-to when all hierarchical data is in the Model already.

6 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Ian asked on 16 Aug 2013, 08:58 PM
I am using MVC Grid to create a Master/Detail Grid.  

Model.Customers, each Customer has an Orders collection (Master/Detail)

The Master Gird binds to Customers fine, but how do I tell the detail grid for each row in the master that the data is in the grid. I'm missing the linkage between the two.

The Kendo Demos have the grid going to the server each time the user clicks the Master row, but I have the data already in the Model so just need an example on how to bind it all up.

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Aug 2013, 02:13 PM
Hello,

If you wish to set the detail Grid data from the master Grid data then you should use the detail Grid dataSource data method in the master Grid the detailInit event:

function detailInit(e) {       
    var detailGrid = e.detailCell.find("[data-role=grid]").data("kendoGrid");
    detailGrid.dataSource.data(e.data.CollectionFieldName);   
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bill
Top achievements
Rank 1
answered on 04 Apr 2014, 09:42 PM
I'm having the same issue.  Did you ever figure it out?  The response given was totally useless.
0
Daniel
Telerik team
answered on 08 Apr 2014, 01:52 PM
Hello Bill,

Is the scenario the same as the one that Ian described? If you are using and the MVC wrappers and the detail grid data should be populated from the master model then the approach from my previous reply should be used to set it. There isn't a way to automatically pass the data to the detail Grid.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bill
Top achievements
Rank 1
answered on 08 Apr 2014, 02:45 PM
So where does the code in your answer go?  I'm using Razor and none of your examples explain this.

Here is how I solved it, kind of.  I still cannot create a separate detail grid.

@(Html.Kendo().Grid(Model.cs_Loan_Information)
.Name("LoanMasterGrid")
.Columns(columns =>
{
columns.Bound(o => o.loan_id);
columns.Bound(o => o.loan_name);
columns.Bound(o => o.loan_officer).Hidden();
columns.Bound(o => o.prin_int_payment);
})

.Pageable() // Enable paging
.Sortable() // Enable sorting
.Filterable()
.Groupable()
.DetailTemplate(@<text>
@(Html.Kendo().Grid(item.Property_Details)
.Name(String.Concat("Property_Details_",item.loan_id.ToString()))
.Columns(columns=>
{
columns.Bound(o=>o.Land_value);
columns.Bound(o=>o.Legal_description);
}))
</text>)

)

0
Daniel
Telerik team
answered on 10 Apr 2014, 09:43 AM
Hello,

The code from my example is for a detailInit event handler which can be specified with the wrapper Events method. The approach should be used when using Ajax hierarchy and not server hierarchy which seems to be used from the code that you provided. 
I am not sure if I understand what you mean by  "separate detail grid". Could you clarify? If you wish to add another grid to the detail then it should be possible to use the same approach:
DetailTemplate(@<text>
    @(Html.Kendo().Grid(item.Property_Details)
        .Name(String.Concat("Property_Details_",item.loan_id.ToString()))
        .Columns(columns=>
        {
        columns.Bound(o=>o.Land_value);
        columns.Bound(o=>o.Legal_description);
        })
    )
     
    @(Html.Kendo().Grid(item.OtherCollectionFieldName)
        .Name(String.Concat("Other_Details_",item.loan_id.ToString()))
        ...
    )
</text>)


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bill
Top achievements
Rank 1
answered on 15 Apr 2014, 08:04 PM
Thanks.. exaclty what I was looking for. 
Works great...
Tags
Grid
Asked by
Ian
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Bill
Top achievements
Rank 1
Share this question
or