I am using kendo mvc razor grid.
version: 2015.1.408.545.
I am working on providing inline editing. In it their is one column which is having dropdown and it is bound through editor for template like this.
@(Html.Kendo().DropDownList()
.Name("ParentGraphicsCategoryID").HtmlAttributes(new { @style = "font-size:12px", id = "ParentGraphicsCategoryID" })
.DataTextField("Text")
.OptionLabel("- Select Parent Graphic Category - ")
.DataValueField("Value")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGraphicCategories", "CommonLookUp");
});
}))
The problem is : How to pass an additional parameter like id which is unique for every row , While calling "GetGraphicCategories" action method in above code ?
By following this link: http://www.telerik.com/forums/pass-grid-view-model-data-to-editor-template
@(Html.Kendo().DropDownList()
.Name("ParentGraphicsCategoryID").HtmlAttributes(new { @style = "font-size:12px", id = "ParentGraphicsCategoryID" })
.DataTextField("Text")
.OptionLabel("- Select Parent Graphic Category - ")
.DataValueField("Value")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetGraphicCategories", "CommonLookUp").Data("getParentID()");
});
}))
function getParentID() {
var row = $(event.srcElement).closest("tr");
var grid = $(event.srcElement).closest("[data-role=grid]").data("kendoGrid");
var dataItem = grid.dataItem(row);
//where the OrderID is the model ID
return { statusId: dataItem.StatusId } }
It is suggeted in above url's code. But unable to get row value while calling "getParentID()" in "Data" method as it is called through dropdowns editor for template .Hence grid variable value is null.
Code for creating Grid is below:
@(Html.Kendo().Grid<GraphicsCategoryModel>()
.Name("GraphicsCategory")
.Columns(columns =>
{
columns.Bound(a => a.GraphicsCategoryName).Title("Graphics Category Name").Width(150);
columns.Bound(a => a.ParentGraphicsCategoryName).EditorTemplateName("ParentGraphicCategoryList").Title("Parent Graphics Category Name").Width(150);
columns.Command(command => { command.Edit(); }).Title("Actions").Width(70);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(pageable => pageable.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Events(events => { events.Error("error_handler"); })
.ServerOperation(true)
.Model(model =>
{
model.Id(p => p.GraphicsCategoryID);
model.Field(p => p.GraphicsCategoryID).Editable(false);
})
.Create(update => update.Action("InsertOrUpdateGraphicsCategory", "GraphicsCategories"))
.Update(update => update.Action("InsertOrUpdateGraphicsCategory", "GraphicsCategories"))
.Destroy(update => update.Action("DeleteAdminAreaOwnership", "AdminAreaOwnership"))
.Read(read => { read.Action("GetAllGraphicsCategories", "GraphicsCategories"); read.Type(HttpVerbs.Get); })
).Events(p => p.DataBound("generalColumnBound")))