2013-03-01 47 views
-1

我製作了html模板,並且在彈出式編輯器中使用了該模板。如果我在網格中至少有一條記錄,那麼它將完美,但如果網格中沒有數據,那麼if點擊添加按鈕,然後自定義彈出編輯器將不會打開。沒有錯誤,但彈出編輯器不打開。所以任何人都知道這個問題的解決方案?在此先感謝。 編輯 這是我用過的模板。當網格爲空時,自定義彈出式編輯器無法打開

<script id="teamEditorTemplate" type="text/x-kendo-template"> 
    <form method="POST"> 
<table> 
      <tr> 
       <td><div > 
         Area Prefix:     
        </div></td> 
       <td><div> 
         <input name="area_prefix" class="k-input k-textbox" style="text-align: left" id="area_prefix" required validationMessage="Please Enter Area Prefix"/>       
        </div></td> 
      </tr> 
      <tr> 
       <td><div > 
         Area Name:     
        </div></td> 
       <td><div> 
         <input name="area_name" class="k-input k-textbox" style="text-align: left" id="area_name" required validationMessage="Please Enter Area Name"/>       
        </div></td> 
      </tr> 
      <tr> 
       <td><div > 
         Source:     
        </div></td> 
       <td><div> 
         <input name="source" style="text-align: left" id="source" required validationMessage="Please Select Source"/>       
        </div></td> 
      </tr> 
      <tr> 
       <td><div > 
         Country Name:     
        </div></td> 
       <td><div> 
         <input name="vox_country_id" style="text-align: left" id="vox_country_id" required validationMessage="Please Select Country"/>       
        </div></td> 
      </tr> 

    </table> 
    </form>  
</script> 

劍道UI代碼是在這裏

$("#grid").kendoGrid({ 
      dataSource: dataSource, 
      pageSize: 10, 
      serverPaging: true, 
      serverSorting: true, 
      sortable:true, 
       pageable: { 
          refresh: true, 
          pageSizes:[10,20,50,100] 
         }, 
      height: 400, 
      toolbar: [{ name: "create", text: "Add New Area" }], 
      columns: [ 
       { field:"area_prefix", title: "Area Prefix",width:70 }, 
       { field: "area_name", title:"Area Name",width:90}, 
       { field: "source", title:"Source",width:70, template: '#= getsourceName(source) #'}, 
       { field: "vox_country_id", width:70,template: '#= getCountryName(vox_country_id) #'}, 
       { command: ["edit", "destroy"], title: "Action",width:53}], 
      editable: { 
       mode: "popup",    
       template: $("#teamEditorTemplate").html(), 
       update: true, 
       add:true, 
       destroy: true, 

       confirmation: "Are you sure you want to remove ?" 
      }, 
      edit: function(e) { 
       if(!e.model.id){ 
        $(e.container).parent().find('.k-window-title').html("Add Area Details"); 
        $(e.container).parent().find('.k-grid-update').html("Save"); 
       } 
      } 
     }); 
+1

很難幫助沒有任何代碼示例都沒有。你能提供一個展示問題的jsFiddle或代碼示例嗎? – nukefusion 2013-03-01 14:28:16

+0

你應該提供一些確切的代碼,因爲我已經嘗試創建一個空網格並打開彈出式編輯器。模板是怎樣的?你如何使用它? – OnaBai 2013-03-02 00:06:05

+0

請檢查上面編輯的問題。我已經把模板和劍道網格的代碼。 – jugni 2013-03-04 08:35:13

回答

0

有一人失蹤在你的問題的信息:你是怎麼定義的數據源,什麼是getsourceNamegetCountryName

嘗試重現你的問題,我寫的是DataSource如下:

var dataSource = new kendo.data.DataSource({ 
    data : [], 
    schema: { 
     model: { 
      id   : "id", 
      fields  : { 
       area_prefix : { type: "string" }, 
       area_name  : { type: "string" }, 
       source  : { type: "string" }, 
       vox_country_id: { type: "string" } 
      }, 
      getsourceName : function (d) { 
       d = d || "hello"; 
       return d; 
      }, 
      getCountryName: function (d) { 
       d = d || "bye"; 
       return d; 
      } 
     } 
    } 
}); 

getsourceName返回或者d(當前值),如果它被定義,而不是nullhello。類似於getCountryName

當你添加一條記錄時,沒有以前的值,它很可能會拋出一些錯誤,無法打開彈出窗口。

但是,如果方便地檢查null,那麼它應該工作正常。

見,我與你的代碼在這裏放在一起的例子:http://jsfiddle.net/OnaBai/wcZ3L/

相關問題