[英]how to load view in Popup editing in kendo grid
我是KendoUI的入門者,我編寫了用於創建網格的代碼
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Groupable(false).Visible(false);
columns.Bound(p => p.BrandName);
columns.Bound(p => p.BrandAbbr);
columns.Bound(p => p.SrcImage);
columns.Bound(item => @item.Id).Title("Command").Filterable(false).Groupable(false)
.Template(@<text>
@Html.ActionLink("Edit", "Edit", new {id = @item.Id}, new {@class = "k-button k-button-icontext k-grid-Edit"})
@Html.ActionLink("Delete", "Delete", new {id = @item.Id}, new {@class = "k-button k-button-icontext k-grid-Delete"})
</text>).Width(200);
});
})
.ToolBar(toolbar =>
{
toolbar.Custom().Action("Create","Brand").Text("add");
}
)
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new {style = "height:500px;"})
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(item => item.Id))
))
在這個網格中,我有刪除和編輯命令。 我想要當用戶單擊“編輯”按鈕進入網格視圖時以彈出形式顯示。 但是我不知道該怎么做。 請幫我。 謝謝大家
為此,您將必須使用“ Custom command
, kendoWindow
(顯示彈出窗口)和template
(顯示彈出窗口內部的內容)。
在網格中
columns.Command(command => command.Custom("Edit").Click("editItem"));
然后(單擊“編輯”時會發生什么。)定義窗口的模板。
<script type="text/x-kendo-template" id="template">
<div id="details-container"> <!-- this will be the content of the popup -->
BrandName: <input type='text' value='#= BrandName #' />
.....
.....
</div>
</script>
<script type="text/javascript">
var detailsTemplate = kendo.template($("#template").html());
function editItem(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var wnd = $("#Details").data("kendoWindow");
wnd.content(detailsTemplate(dataItem));
wnd.center().open();
}
</script>
這是更好的選擇- 演示彈出式編輯
在網格的列聲明部分,
.Columns(columns =>
columns.Command(command => {
command.Edit(); //for edit functionality
command.Destroy(); //for delete functionality
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Create(update => update.Action("EditingInline_Create", "Grid"))
.Read(read => read.Action("EditingInline_Read", "Grid"))
.Update(update => update.Action("EditingInline_Update", "Grid"))
.Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.