Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create custom kendo.ui.Window for edit in kendo.ui.grid

I'm starter in kendo.Ui , i write this code for create grid

@(Html.Kendo().Grid<BrandViewModel>(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.BrandName);
        columns.Bound(p => p.BrandAbbr);
        columns.Bound(p => p.SrcImage);

        columns.Command(command => command.Custom("Edit").Click("editItem"));

    })

    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("CustomCommand_Read", "Brand"))
         .Model(model => model.Id(p => p.Id))

               )
)

i want when user click in Edit button open Edit view in kendo window i write this code

@(Html.Kendo().Window().Name("Details")
    .Title("Customer Details")
    .Visible(false)
    .Modal(true)
    .Draggable(true)

    .Width(300)
)



<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>

and java script code:

<script type="text/javascript">
    var detailsTemplate = kendo.template($("#template").html());

    function editItem(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        $("#Details").data("kendoWindow").refresh({
            url: "/Brand/Edit/" + dataItem.Id
        });
        $("#Details").data("kendoWindow").open();



    }
</script>

this code work fine For the first time I click on a button,But when I click a second time.I encountered the following error

0x800a138f - JavaScript runtime error: Unable to get property 'refresh' of undefined or null reference

please help me, thanks all

like image 890
Pouya Avatar asked Aug 09 '13 14:08

Pouya


People also ask

How do I get the edited row in kendo grid?

dataSource. get(e. model. get("Id")) gets the newly added row, but if multiple rows were added before saving, it will always get the first added row ("Id" is set to auto increment and is automatically generated by the database server, therefore all newly created rows will initially have 0 before saving).

How do I change my Kendo grid theme?

Just replace kendo. default. min. css file from the <head> section of the page with the name of the theme you would like to use.

What is autoBind Kendo?

autoBind Boolean (default: true)By default, autoBind is set to true and the widget will bind to the data source specified in the configuration. Setting autoBind to false is useful when multiple widgets are bound to the same data source.


2 Answers

I remember I had a similar issue with this control. Now it works for me with the following Javascript code :

<script type="text/javascript">
    var detailsTemplate = kendo.template($("#template").html());
    var windowObject;

    $(document).ready(function () {
        windowObject = $("#Details").data("kendoWindow");
    });

    function editItem(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        windowObject.refresh({
            url: "/Brand/Edit/" + dataItem.Id
        });
        windowObject.open();
    }
</script>

Hope it helps !

like image 194
Joffrey Kern Avatar answered Oct 31 '22 05:10

Joffrey Kern


The problem is that, by default, the window will be destroyed (removed from the DOM) on closure. I would suggest removing the "undefined" condition i added in the example below and, instead, dont create the "Details" div in the first place.

<script type="text/javascript">
    var detailsTemplate = kendo.template($("#template").html());

    function editItem(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        if($("#Details") == undefined)
            $("body").append("<div id=\"Details\"></div>

        $("#Details").data("kendoWindow").refresh({
            url: "/Brand/Edit/" + dataItem.Id
        });
        $("#Details").data("kendoWindow").open();



    }
</script>
like image 38
Pluc Avatar answered Oct 31 '22 04:10

Pluc