2013-03-01 54 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/

相关问题