3

I have a Grid with Employes. There is a Edit button and the edit mode is set to Popup. In the EditorTemplate of the entity I want to edit, there is another grid that has a history of Salary with a incell or inline edit mode.

Both grids uses Ajax datasources. The problem is with the inner grid binding. The controller action feeding a Json result to the ajax call requires the ID of the employe we are editing to return the appropriate Salary history. However, Kendo UI ASP.NET MVC wrapper will render some sort of template of the editor before knowing which employee we want to edit, then it will edit it when we are requesting the popup.

How can I feed the Employe ID in the Read Ajax call?

Main Grid

@(Html.Kendo().Grid<MyProject.Business.Models.EmployeDTO>().Name("EmployeGrid")
.ToolBar(toolbar => toolbar.Create())
.Columns(cols =>
{
    cols.Bound(o => o.someData).Title("Some Data");
    cols.Bound(o => o.moreData).Title("More Data");
    cols.Command(o =>
    {
            o.Edit();
        o.Destroy();
    }).Title("&nbsp;");
})
.Editable(editor => editor
    .Mode(GridEditMode.PopUp)
    .Window(window => window.Draggable().Resizable().HtmlAttributes(new { @style = "width:700px;" })))
.Sortable()
.Filterable()
.Groupable()
.DataSource(datasource => datasource
    .Ajax()
    .Model(model => model.Id(o => o.id))
    .Read(read => read.Action("GetAll", "EmployesAjax"))
    .Update(update => update.Action("Update", "EmployesAjax"))
    .Create(create => create.Action("Create", "EmployesAjax"))
    .Destroy(destroy => destroy.Action("Destroy", "EmployesAjax"))
    )
)

Inner Grid (In Views/Shared/EditorTemplates/EmployeDTO.cshtml)

@Html.Kendo().Grid<MyProject.Business.Models.SalairyDTO>().Name("SalaryGrid")
.Columns(cols =>
{
    cols.Bound(o => o.someInfo).Title("Some Info");
})
.DataSource(datasource => datasource
    .Ajax()
    .Model(model =>
    {
        model.Id(o => o.id);
        model.Field(o => o.employe_id).DefaultValue(Model.id);
    })

    // NEED THE ID HERE
    .Read(read => read.Action("GetByEmployeId", "SalairyAjax", new { id = "" }))

    .Update(update => update.Action("Update", "SalairyAjax"))
    .Create(create => create.Action("Create", "SalairyAjax"))
    .Destroy(destroy => destroy.Action("Destroy", "SalairyAjax"))));
4

2 回答 2

3

基本上,我建议您将内部 Grid 的 AutoBind 选项设置为 false 并使用外部 Grid 的编辑事件来执行读取请求并将值作为附加参数传递。

这是一个例子:

function onEditOfEmployeGrid(e){
    $('#SalaryGrid').data().kendoGrid.dataSource.read({id:e.model.EmployeeID})
}
于 2012-11-14T19:35:37.000 回答
0

您可以简单地使用网格中的 addtionaldata 参数从网格中传递值。然后可以使用 ViewData["RouteID"] 在网格弹出编辑器中引用(左侧)上的 RouteID。我希望这会有所帮助

     .Editable(editable => editable.Mode(GridEditMode.PopUp)
         .TemplateName("busStop")
         .DisplayDeleteConfirmation(true)
         .Window(window => window.Modal(true).Resizable().Draggable())
         .AdditionalViewData(new { RouteID = Model.RouteID }))
于 2013-03-22T15:55:59.823 回答