I have a parent hierarchy grid that have a child table for each of the parent row. I have a custom command button in child table rows and want to access the parent row ID when I press that button. Here is my code :
Parent Table :
@(Html.Kendo().Grid<FsERP.Models.ParentModel>()
.Name("gridParent")
.Columns(columns =>
{
columns.Bound(p => p.ID).Hidden(true);
columns.Bound(p => p.P_Column1).Width(180);
columns.Bound(p => p.P_Column2).Width(180);
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.ID);
model.Field(p => p.ID).Editable(false););
})
.PageSize(20)
.Read(read => read.Action("EditingCustom_Read", "Parent"))
).ClientDetailTemplateId("childsTemplate")
Child Table Template :
<script type="text/kendo" id="childsTemplate">
@(Html.Kendo().Grid<FsERP.Models.ChildModel>()
.Name("gridChild")
.Events(e => e.DataBound("OnDataBound").Edit("OnEdit"))
.Columns(columns =>
{
columns.Bound(c => c.ID).Hidden(true);
columns.Bound(c => c.C_Column1).Width(180);
columns.Bound(c => c.C_Column2).Width(130);
columns.Command(command =>command.Custom("GetParentID").Click("showParentID")).Width(80);
}).DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.ID);
model.Field(p => p.ID).Editable(false););
})
.PageSize(20)
.Read(read => read.Action("EditingCustom_Read", "Child"))
).ToClientTemplate()
)
</script>
Here is my javascript click method :
function showParentID(e) {
}
How would I alert the parent ID inside this showParentID() method. Any help would be appreciable.
Thanks.
NOTE
I dont want to send the parentID in parameter of the javascript method as I also need to access the event information.
You can add parent ID field into your custom Command name like this:
Then inside your showParentID function retrieve the name of the button which has been triggered and split the ID after the underscore or whatever you rather.
Anyhow this is the POV and you could change this scenario in any form you think is better.
Please let me know if it helps or not