2013-08-11 16 views
6

Jestem rozrusznik w kendo.ui, pisałem ten kod, aby utworzyć kendo.ui.gridDlaczego są `dane (" kendogrid ")` Undefined?

@(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)) 
    ) 
) 

Gdy użytkownik kliknie przycisk Edytuj w siatce pokaże Edytuj widok na kendo.ui .window, a użytkownik może edytować dane.

@(Html.Kendo().Window().Name("Details") 
    .Title("Customer Details") 
    .Visible(false) 
    .Modal(true) 
    .Height(400) 
    .Draggable(true) 
    .Width(300) 
    .Events(events => events.Close("onClose")) 
) 

<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()); 
    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.center().open(); 
    } 

    function onClose(e) { 
     var grid = $("#Grid").data("kendoGrid").dataSource.read(); 

    } 

</script> 

ale w onClose metody $("#Grid").data("kendoGrid") jest niezdefiniowany, proszę mi pomóc, dzięki wszystkim zdarzeń obciążenie

+0

całkowicie losowe domysły ... po .Name ("Grid") i .ID ("Grid") –

+0

@ Robert Levy: ID to niezdefiniowana właściwość w kendo.ui .krata. – Pouya

+0

Czy jesteś pewien, że $ ('# Grid'). Length zwraca> 0? – Shion

Odpowiedz

5

try Okno

$(window).load(function() { 
var grid = $("#grid").data("kendoGrid"); 

to praca dla mnie.

+0

$ ("# grid") .danych ("kendoGrid"). DataSource._data – Khoshtarkib

0

var grid = $ ("# Grid") .danych ("kendoGrid"); // wywołanie siatki przez nazwę siatki używanej w brzytwie

Powiązane problemy