2013-08-11 4 views
6

私はkendo.uiでスターターだけど、私は、ユーザーがグリッドで編集ボタンをクリックすると、それはkendo.uiで編集ビューを表示しますkendo.ui.grid`data(" kendogrid ")はなぜ未定義ですか?

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

を作成するには、このコードを書いています.windowを使用し、ユーザーはデータを編集できます。

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

しかし $("#Grid").data("kendoGrid")は未定義である onClose方法では、私を助けてください、おかげですべての

+0

名前(グリッド)と.ID( "グリッド")の後に –

+0

@ Robert Levy:IDはkendo.uiの未定義のプロパティです。 。グリッド。 – Pouya

+0

$( '#Grid')。lengthが> 0を返しますか? – Shion

答えて

5

トライウィンドウのloadイベント

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

私にとって、この作品。

+0

$( "#grid")。data( "kendoGrid")。dataSource._data – Khoshtarkib

0

var grid = $( "#Grid")データ( "kendoGrid"); //罫線で使用したグリッドの名前でグリッドを呼び出す

関連する問題