【问题标题】:How to "Data and a button in same column with kendo grid"如何“使用剑道网格在同一列中的数据和按钮”
【发布时间】:2013-12-25 08:20:11
【问题描述】:

有可能吗?我尝试使用自定义列,但失败了,谁能用剃刀举一个简单的例子吗?

绘画作品:)

我想要这样的东西,列包括数据和一个按钮(带有 onclick)

//---Not Worked 1---

    columns.Command(command =>
    {
        command.Custom("Telefonları Göster").Click("telefonlariGoster");
        columns.Bound(x => x.Adres);
    }).Width(580);
....

//---Not worked 2---

        columns.Template(@<text>
            <label>@item.Adres</label>
            <input type="button" name="AdresGuncelle" value="AdresGuncelle" onclick="telefonlariGoster()" />
    </text>);

//Worked

columns.Bound(x => x.Adres)
     .ClientTemplate("#=Adres#" +
     "<input type='button' class='telefonlariGoster' style='float: right;' name='telefonlariGoster' value='Telefonları Güncelle' onclick='telefonlariGoster()'/>");

【问题讨论】:

  • 我不知道按钮,但似乎剑道支持事件处理。只需通过 css 定位您的列,并为该列中的每一行提供“按钮外观”。您可以在 demos.kendoui.com/web/grid/events.html 上找到有关事件处理的所有信息
  • 这是合乎逻辑的,但必须有办法实现我的愿望。
  • 如果您可以发布您的代码,我可以提供更多帮助,但事实上,您将不得不接受我的回答和文档。
  • 我刚刚意识到你想要一个字段内的命令。忽略我之前的回答。我很抱歉。
  • columns.Command(command =&gt; { command.Custom("viewDetails").Click("showDetails"); command.Custom("AnotherCommand").Text("Another Command"); command.Custom("Custom").Text("Custom Command"); }); 试试这个.. 这将添加三个按钮。在查看它是否完全有效之后,您就会知道我们走在正确的轨道上。我没有剑道,所以我在尝试纯粹的直觉。

标签: asp.net-mvc kendo-ui kendo-grid


【解决方案1】:

尝试在要显示自定义列显示的列中使用 ClientTemplate。 例如:

@(Html.Kendo().Grid(Model)
  .Name("grid")
  .Columns(columns =>
  {
      columns.Bound(x => x.Name)
          .ClientTemplate("#=Name#" +
          "<input type='button' class='className' style='float: right;' name='buttonName' value='Click here' onclick='ButtonClick(\"#=Name#\", this)'/>");
      columns.Bound(x => x.Id);
  })
  .DataSource(dataSource => dataSource
                               .Ajax()
                               .Total(10)
                               .ServerOperation(false)
                             )
  )

在脚本按钮点击功能

function ButtonClick(name, button) {
    alert(name);
}

【讨论】:

  • 非常感谢。这就是我想要的
  • @Goran_Mandic 你说得对,你们俩都值得一票,非常感谢:)
猜你喜欢
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多