2016-11-11 44 views
3

我有一个剑道格栅,看起来有点像这样(代码编辑的清晰度):剑道格,在编辑按钮改变文字

var gridList = $('##listBo').kendoGrid({ 

     ... 

     columns: [ 
      ... 
      { 
       command: "edit" 
       , title: 'Edit' // Need to make this text conditional 
       , width: 91 
      } 
     ] 

     ... 

     , editable: { 
       mode: "popup" 
       , template: $("##addEditPopup").html() 
       , window: { 
       open: loadJSOnWindowLaunch 
       , title: "Reservation request" 
      } 
      } 
     , dataBound: function(e) { 
      dataBoundFunction(); 
     } 

    }).data("kendoGrid"); 

我需要的按钮说,在某些情况下,“编辑”和根据数据源中的值查看其他人。

我该如何做到最好?

回答

2

解决这种情况的一种简单方法是制作一个自定义命令列,然后使用模板选项,根据您的条件渲染列按钮。

尝试这样的:

$("#grid").kendoGrid({ 
        dataSource: dataSource, 
        pageable: true, 
        height: 550, 
        toolbar: ["create"], 
        columns: [ 
         { field:"ProductName", title: "Product Name" }, 
         { field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "120px" }, 
         { field: "UnitsInStock", title:"Units In Stock", width: "120px" }, 
         { field: "Discontinued", width: "120px" }, 
         { template: comandTemplate }], 
        editable: "popup" 
       }); 
      }); 
      // render command column button based on condition 
      function comandTemplate(model){ 
       // here i use Discontinued attribute to data model to show 
       // view detail button or edit button 
       if(model.Discontinued==0) 
       { 
        return '<a class="k-button k-button-icontext k-grid-edit" href="#"><span class="k-icon k-edit"></span>Edit</a>'; 
       } 
       else 
       { 
        return '<a class="k-button k-button-icontext" href="javascript:void(0)" onclick="viewDetailsAction()">View Details</a>'; 
       } 
      } 
      // Custom action if view detail button click 
      function viewDetailsAction() 
      { 
       alert("Your custom action for view detail"); 
      } 

这里是工作示例http://dojo.telerik.com/AdAKO

我希望这会帮助你。

+0

你试过我的解决方案吗?这是你想要的吗? –

+0

嗨。在我问这个问题之前,我尝试了一些类似的东西。我遇到的问题是,如果您查看我的原始代码,当按下'编辑'按钮时,我需要执行'可编辑'节点中的所有内容(即启动弹出窗口,运行JS函数等)。我怎样才能使用你的解决方案,并仍然让这些东西运行? – Junglefish

+0

嗨迈克尔,如果你检查我创建的演示,你可以看到编辑弹出窗口工作得很好。如果你想在事件上执行任何功能,你可以像往常一样。让我知道你想要在什么事件上执行什么功能。 –

0

你只需要在列添加自定义列这样

{ 
    template: "# if (property == true) { # <a class="k-button k-grid-edit" 
    href="#"><span class="k-icon k-edit"></span>Edit</a> # } else { # 
    <a class="k-button"><span onClick="callFunction()" 
    </span>View</a> # } #", width: "150px" 
} 
  • 其中“财产”是指将用作条件字段,以显示不同的按钮的字段。

希望,这将为你工作。 (ThumbsUp)