2012-12-24 45 views
1

現在我想要做的是混合或服務器控件和JavaScript。我認爲劍道服務器控件是優雅的。 正如你可以看到我desparately試圖找到如何在電網接入可編輯的財產,但沒有luck.I認爲這將是我明白如何使用模板與腳本但不與服務器控件

var grid = $("#Grid").data("kendoGrid"); 
grid.editable.template = function() { kendo.template($("#MyTemplate").html()) }; 

的想法是,當編輯按鈕,他們得到一個用戶點擊看到#MyTemplate而不是kendo默認的html版本。也許,我需要走另一個方向,請引導我。

這是我的完整代碼僅供參考。

@model IEnumerable<Msh.Intranet.Models.ApiAdFileDisplayGridModel> 
<script type="text/x-kendo-template" id="myTemplate">   
      <input data-bind="value: Id" name="Id"/> 
     </script> 
@(Html.Kendo().Grid(Model) 
    .Name("Grid") 
    .Columns(columns => 
    { 
     columns.Bound(p => p.Id).Visible(false); 
     columns.Bound(p => p.FileName).Visible(false); 
     columns.Bound(p => p.FormNumber); 
     columns.Bound(p => p.FormTitle); 
     columns.Bound(p => p.Class); 
     columns.Bound(p => p.SecondaryCategory).Title("Category") ; 
     columns.Bound(p => p.RevisionDate).Format("{0:MM/dd/yyyy}"); 
     columns.Command(c => 
     { 

      c.Edit(); 
      c.Destroy(); 
     }); 

    }) 
    .Selectable() 
    .Groupable() 
    .Pageable() 
    .Filterable() 
    //.Sortable() 
      .ToolBar(tools => 
     { 
      tools.Create(); 
     }) 
     .Editable(editor => editor.Mode(GridEditMode.PopUp)) 
    .DataSource(dataSource => dataSource 
     .Ajax() 

     //this tells kendo I am the primary key 
      .Model(model => 
      { 
       model.Id(p => p.Id); 
       model.Field(p => p.RevisionDate); 
      }) 
     .Read(read => read.Url(@Url.Action("ApiAdFileDisplayGrid","api",null,null)).Type(HttpVerbs.Get)) 
     .Create(create=>create.Url(@Url.Action("ApiAdFileDisplayGrid","api",null,null)).Type(HttpVerbs.Post)) 
     .Update(update=>update.Url(@Url.Action("ApiAdFileDisplayGrid","api",null,null)).Type(HttpVerbs.Put)) 
     .Destroy(destroy=>destroy.Url(@Url.Action("ApiAdFileDisplayGrid","api",null,null)).Type(HttpVerbs.Delete)) 
    ) 
) 
<script type="text/javascript"> 

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

     //grid.bind("change", function() { 
     // alert("Change "); 
     //}); 

     grid.bind("dataBound", function (data) { 
      alert("dataBound"); 

     }); 

     grid.bind("edit", function (e) { 

      if (e.model.isNew()) { 

       //create 
       alert("new"); 


      } else { 

       //edit 
       alert("edit"); 

      } 

     }) 

    // WebAPI needs the ID of the entity to be part of the URL e.g. PUT /api/Product/80 
    grid.dataSource.transport.options.update.url = function (data) { 
     var baseUrl = "@Url.Content("~/api/ApiAdFileDisplayGrid/")" +data.Id; 
     return baseUrl; 
    } 

    // WebAPI needs the ID of the entity to be part of the URL e.g. DELETE /api/Product/80 
    grid.dataSource.transport.options.destroy.url = function(data) { 
     var baseUrl = "@Url.Content("~/api/ApiAdFileDisplayGrid/")" + data.Id; 
     return baseUrl; 
    } 
     grid.editable.template = function() { kendo.template($("#MyTemplate").html()) }; 
}); 

</script> 

回答

2

要定製編輯器,您應該使用MVC編輯器模板引擎。代碼庫遵循this的方法。

+0

但我如何訪問kendo asp mvc html助手創建的javascript屬性。 – hidden

+0

我只是回顧編輯器模板的方式。這是天才的感謝! – hidden

+0

不要忘記接受和新年快樂(: –

相關問題