how to Change Caption of popup kendo grid by html

2019-06-20 16:57发布

问题:

I am using the popup kendo grid and i use add new record and edit mode and i want change caption of popup window kendo grid by html helper when i add new record.

    <div class="k-rtl">

    @(Html.Kendo().Grid<KendoSample.Models.Person>()
   .Name("grid")
   .Columns(columns =>
    {
        columns.Bound(p => p.PersonId).Title("Person Code").Width(100).Sortable(true);
        columns.Bound(p => p.Name).Title("Name").Width(200).Sortable(true);
        columns.Bound(p => p.Family).Title("Family").Sortable(false);
        columns.Command(c => { c.Edit().Text("Edit").CancelText("Cancel").UpdateText("save"); c.Destroy().Text("Delete"); });            
    })
.Pageable()

.ToolBar(s => { s.Create().Text("ایجاد"); })
.Editable(c => { c.TemplateName("Default").Mode(GridEditMode.PopUp); c.Window(x => x.Title("ویرایش")); })


.Scrollable()
.Sortable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
    .Ajax()
                            .Model(c => c.Id(p => p.PersonId))
                            .Create(c => c.Action("Read", "Home"))

    .Read(read => read.Action("EditingPopup_Read", "Grid"))
    .Update(update => update.Action("EditingPopup_Update", "Grid"))
    .Destroy(update => update.Action("EditingPopup_Destroy", "Grid"))                                


                            .ServerOperation(true)
    .PageSize(8)
    .Read(read => read.Action("EditingPopup_read", "Home"))
 )
 .Sortable()
 .Filterable()
 )

</div>

please tell me how to change caption of popup window in add mode.

回答1:

i fix this issue by use edit event.

.Events(events => events.Edit("insertPopupCaption")

<script>
 function insertPopupCaption(e) {
 if (e.model.isNew()) {
     $('.k-window-title').text("add");        
 }   
}
</script>


回答2:

@Iraj, the problem with matching on $('.k-window-title') is that it will change the caption for every Kendo UI window on that page. I have a nested grid entry page where the second grid was in a popup window. As a work around, I put my edit template inside a div with a class of "bdPopup". Then to get the caption of that form, I used the following syntax:

$(".bdPopup").parent().parent().parent().children(".k-window-titlebar").children(".k-window-title").text("Add")


回答3:

You can change title in grid edit event.

    grid.bind("edit", function (event) {
    event.container.parent().find('.k-window-title').text(event.model.isNew() ? "New" : "Edit");
});


回答4:

Not a direct answer to your question. But I am doing the following for the title of my kendowindow

        drilldownpopup.data('kendoWindow').title("My Title");
        $('.k-window-actions').html('<span class="titletext">' + "Make & Hold Details" + '</span><a href="#" class="k-window-action k-link"><span class="k-icon k-i-close"></span></a>');


回答5:

Here is another way.

@(Html.Kendo().Grid<Model>()
....
....
....
.Events(events =>
    {
        events.Edit("onEditKendoGrid");
    })
)

<script>
function onEditKendoGrid(e) {
    //set edit window title
    e.container.kendoWindow("title", "Title goes here...");
}
</script>