2013-10-01 48 views
0

请仔细阅读下面的代码。在下面的网格中,我有一个超链接的列。我想打开一个kendo窗口,当我点击特定的链接。我怎样才能做到这一点。目前它正在导航到其他页面。如何打开kendo窗口点击

@model IEnumerable<WeBOC.Support.Entities.ImportUnit> 

@{ 
    ViewBag.Title = "Import Units"; 
} 

<h2>Import Units</h2> 

@(Html.Kendo().Grid(Model) 
    .Name("Grid") 
    .Columns(columns => 
    { 
     columns.Bound(p => p.UnitNbr).Width(150).ClientTemplate(@Html.ActionLink("#=UnitNbr#", "UnitInspector", new { id = "#=UnitId#" }).ToHtmlString()).Title("Unit No."); 
     columns.Bound(p => p.VIRNbr).Width(150).Title("VIR No."); 
     columns.Bound(p => p.BLNbr).Width(150).Title("BL No."); 
     columns.Bound(p => p.IGMStatus).Width(80).Title("IGM Status"); 
     columns.Bound(p => p.LineCode).Width(80).Title("Line Code"); 
     columns.Bound(p => p.Arrived).Format("{0:dd/MM/yyyy HH:mm}").Width(150).Title("Arrived"); 
    })  
    .Groupable() 
    .Pageable() 
    .Sortable() 
    .Filterable()  
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(20) 
     .ServerOperation(false) 
    ) 
) 

回答

0

为什么不将您的客户端模板更改为简单的html元素,比如a元素并将javascript函数分配给打开窗口的此元素?

... 
columns.Bound(p => p.UnitNbr).Width(150).ClientTemplate("<a id="myId>Unit No.</a>); 
... 

,然后使用jquery:

$("#myId").click(function() { 
    $("#kendoWindow").data("kendoWindow").open(); 
}); 
+0

上面的代码是不工作。事实上,我认为这个函数根本就没有被调用。我也通过在该函数中使用alert来测试,但没有回应。其次,我可能需要在同一页面上定义一个kendo窗口吗? – user2542561

+0

我忘了一些“在我的代码中,模板应该是”Unit No.“ – Lopo

0

如何创建超链接,如何调用JavaScript函数,以及如何传递参数是在文档的this部分全部覆盖。

0

调整你的模板,这样的链接有一个CSS类:

columns.Bound(p => p.UnitNbr).Width(150).ClientTemplate(@Html.ActionLink("#=UnitNbr#", "UnitInspector", new { id = "#=UnitId#" }, new { @class="someclass" }).ToHtmlString()).Title("Unit No."); 

然后使用jQuery:

$(document).on("click", ".someclass", function (e) { 
    e.preventDefault(); 
    var address = $(this).attr("href"); 
    $("<div/>").kendoWindow({ 
     content: address 
    }).data("kendoWindow").open(); 
});