Kendo ui 如何在剑道网格单元内显示剑道网格?
我在MVC应用程序中使用剑道网格来显示数据。它工作得非常好。但我想展示网格单元中的另一个网格。我做了研究,尝试了不同的方法,但没有找到任何解决办法。请建议。 这是我的密码Kendo ui 如何在剑道网格单元内显示剑道网格?,kendo-ui,kendo-grid,kendo-asp.net-mvc,Kendo Ui,Kendo Grid,Kendo Asp.net Mvc,我在MVC应用程序中使用剑道网格来显示数据。它工作得非常好。但我想展示网格单元中的另一个网格。我做了研究,尝试了不同的方法,但没有找到任何解决办法。请建议。 这是我的密码 @(Html.Kendo().Grid<TimeSheetManagement.Models.ClientView>() .Name( "Clients" ) .Columns( columns => { columns.Bound( e => e.Name ); columns.Bou
@(Html.Kendo().Grid<TimeSheetManagement.Models.ClientView>()
.Name( "Clients" )
.Columns( columns =>
{
columns.Bound( e => e.Name );
columns.Bound( e => e.Address );
columns.Bound( e => e.City );
columns.Bound( e => e.State );
columns.Bound( e => e.ZipCode );
columns.Template( e => e.Contacts ).ClientTemplate( "#= buildContactsGrid(data) #" );
columns.Bound( e => e.CreatedDate );
columns.Bound( e => e.CreatedBy );
columns.Bound( e => e.UpdatedDate );
columns.Bound( e => e.UpdatedBy );
columns.Bound( "" ).ClientTemplate( @Html.ActionLink( "Edit" , "Create" , new { clientId = "#=Id#" } , new { title = "Edit Client" } ).ToHtmlString() );
} )
.Pageable().Sortable().Filterable()
.AutoBind( true )
.DataSource( source => source.Ajax()
.PageSize( 20 )
.Read( read => read.Action( "GetClients" , "Client" ) )
)
)
@(Html.Kendo().Grid())
.名称(“客户”)
.列(列=>
{
columns.Bound(e=>e.Name);
columns.Bound(e=>e.Address);
columns.Bound(e=>e.City);
columns.Bound(e=>e.State);
columns.Bound(e=>e.ZipCode);
columns.Template(e=>e.Contacts).ClientTemplate(“#=buildContactsGrid(data)#”);
columns.Bound(e=>e.CreatedDate);
columns.Bound(e=>e.CreatedBy);
columns.Bound(e=>e.updateDate);
columns.Bound(e=>e.UpdatedBy);
columns.Bound(“”).ClientTemplate(@Html.ActionLink(“编辑”,“创建”,新建{clientId=“#=Id#”},新建{title=“编辑客户端”}).ToHtmlString());
} )
.Pageable().Sortable().Filterable()
.AutoBind(真)
.DataSource(source=>source.Ajax()
.页面大小(20)
.Read(Read=>Read.Action(“GetClients”、“Client”))
)
)
这是我的JavaScript函数
<script>
function buildContactsGrid(client)
{
var htmlContacts = '';
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '@Url.Action( "GetJsonContactsByClientId" )',
data: JSON.stringify({
'sClientId': client.Id
}),
dataType: "json",
async: false,
success: function (response) {
htmlContacts += "<table style='border:1px solid black;'><tr><th>First Name</th><th>Last Name</th><th>Role</th></tr><tr>";
$(response).each(function (index, item) {
htmlContacts +="<td>"+ item.FirstName +"</td><td>"+ item.LastName+"</td><td>"+item.Role +"</td></tr>";
});
htmlContacts += "</table>";
}
});
return htmlContacts;
}
</script>
函数buildContactsGrid(客户端)
{
var htmlContacts='';
$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:'@url.Action(“GetJsonContactsByClientId”),
数据:JSON.stringify({
“sClientId”:客户端Id
}),
数据类型:“json”,
async:false,
成功:功能(响应){
htmlContacts+=“第一名最后一名角色”;
$(响应)。每个(功能(索引,项目){
htmlContacts+=“”+item.FirstName+“”+item.LastName+“”+item.Role+“”;
});
htmlContacts+=“”;
}
});
返回htmlContacts;
}
我能够用JavaScript函数构建一个表并在网格单元格中显示,但我想显示剑道网格
在谷歌上花了几天时间做了一些研究之后,我发现了这篇文章,他们解释了为什么客户端模板没有被绑定到负载上 这是我在网格单元中的网格:
columns.Template( e => "" ).Title("Contacts").ClientTemplate(
Html.Kendo().Grid<TimeSheetManagement.Models.ContactView>()
.Name( "Clients_#=Id#" )
.Columns( c =>
{
c.Bound( e1 => e1.FullName );
c.Bound( e1 => e1.Role );
c.Bound( e1 => e1.Email );
c.Bound( e1 => e1.PhoneNumber );
} )
.AutoBind( true )
.DataSource( source1 => source1.Ajax()
.PageSize( 5 )
.Read( read1 => read1.Action( "GetContactsByClientId" , "Client" , new { sClientId = "#=Id#" } ) )
)
.ToClientTemplate()
.ToHtmlString()
);
最后,我在脚本中添加了这段代码
function onGridDataBound(e)
{
$('#Clients script').appendTo(document.body);
}
这是我预期的输出。如果您有任何问题,请告诉我。伙计们,我已经添加了代码。请查看我的代码并让我知道。非常感谢。
function onGridDataBound(e)
{
$('#Clients script').appendTo(document.body);
}