简体   繁体   English

Kendo mvc Grid ClientTemplate javascript 功能不起作用

[英]Kendo mvc Grid ClientTemplate javascript function not working

I have a Kendo mvc Grid and using client template as a column and i wrote a javascript function in the template to return the script block but its seems not working and no javascript error.我有一个 Kendo mvc Grid 并使用客户端模板作为一列,我在模板中编写了一个 javascript 函数来返回脚本块,但它似乎不起作用并且没有 javascript 错误。 I also tried to write the script to the client template directly but its not working too.我也尝试将脚本直接写入客户端模板,但它也不起作用。

//html in client template //客户端模板中的html

    .Columns(columns =>
    {

     columns.Template(e =>
     { }).ClientTemplate(

         "<div class='table-responsive'>" +
              "<table border='0' class='table' >" +

                 ...................................                

              "</table>" +
         "</div>"+
          "#=AlignDiv(Id)#"
                         );
      })

//javascript function to return a script block as a string //javascript函数将脚本块作为字符串返回

      <script type="text/javascript">
      function AlignDiv(Id) {
      var result = "<script> $('.calDiv"+Id+"').map(function () {" +
           "return $(this).Height();" +
       "}).get()," +
       "maxHeight = Math.max.apply(null, heights);" +
       "$('.calDiv" + Id + "').height(maxHeight);" +
        "alert('test')<\/script>";
      return result;
  }

Thanks a lot, Dennis非常感谢,丹尼斯

In order to format Kendo Grid Column value with conditionally chosen action you can use one of the suitable examples below.为了使用有条件选择的操作格式化 Kendo Grid Column 值,您可以使用以下合适的示例之一。 For more information: How Do I Have Conditional Logic in a Column Client Template?有关更多信息: 如何在列客户端模板中使用条件逻辑?


UI for Javascript: Javascript 用户界面:

{
    field: "EmployeeName", type: "string", width: "55px", title: "Employee Name", 
            template: "#= GetEditTemplate(data) #"
}


UI for MVC: MVC 的用户界面:

...
columns.Bound(t => t.EmployeeName)
.Title("Status Name")
.Template(@<text></text>)
.ClientTemplate("#= GetEditTemplate(data)#").Width("55px");
...


Javascript Method: Javascript 方法:

<script>
//Change the color of the cell value according to the given condition
function GetEditTemplate(data) {
    var html;

    if (data.StatusID == 1) {
        html = kendo.format(
        //"<a class=\"k-button\" href='" + '@Url.Action("Edit1", "Controller")' + "/{0}" + " '>Edit</a>  ",
        "<span class='text-success'>" +
        data.EmployeeName
        + "</span>"
        );
    }
    else {
        html = kendo.format(
        //"<a class=\"k-button\" href='" + '@Url.Action("Edit2", "Controller")' + "/{0}" + " '>Edit</a>  ",
        "<span class='text-danger'>Cancel</span>"
        );
    }
    return html;
}
</script>

Hope this helps...希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM