页面加载时,我的标记中没有出现我的嵌套模板列。我正在尝试在另一个父网格的DetailView中加载一个带有模板列的网格。我可以看到我的数据被传递,并且显然UnitPeriod的“名称”出现但我的模板列中没有任何内容,所以看起来数据正在传递到网格中。我用firebug检查了源代码,该列总是空载。任何人都可以找到原因吗?
<div>
@(Html.Telerik().Grid<RentableUnit>()
.Name("RentableUnits")
.Columns(columns =>
{
columns.Bound(e => e.UnitID).Hidden();
columns.Bound(e => e.Name).Width(75);
})
.ClientEvents(events => events.OnRowDataBound("employees_onRowDataBound")
.OnDetailViewExpand("unit_onDetailViewExpand")
.OnDetailViewCollapse("unit_onDetailViewCollapse"))
.DetailView(details => details.ClientTemplate(
Html.Telerik().Grid<UnitPeriod>()
.Name("UnitPeriod_<#= UnitID #>")
.Columns(columns =>
{
columns.Bound(o => o.Name);
columns.Template(@<text>
@foreach (Day day in item.Days)
{
if (!day.IsRentable)
{
<img src="../../Content/Images/Houses/icon_lokad.png"/>
}
else
{
<img src="../../Content/Images/Houses/icon_opid.png"/>
}
}
</text>);
})
.ClientEvents(events => events.OnRowDataBound("orders_onRowDataBound"))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("SelectedUnitPeriod", "Home", new { unitId = "<#= UnitID #>" }))
.ToHtmlString()
))
.DataBinding(dataBinding => dataBinding.Ajax().Select("RentableUnits", "Home"))
.Sortable()
)
</div>
<script type="text/javascript">
var derpinski = "";
function expandFirstRow(grid, row) {
if (grid.$rows().index(row) == 0) {
grid.expandRow(row);
}
}
function loadTabGridContent(e) {
var url = '/Home/TabGridContent/';
$.ajax({
type: 'GET',
dataType: 'html',
url: url,
success: function (data) {
alert('success');
$('#TabGridContent').html(data);
}
});
}
function employees_onRowDataBound(e) {
var grid = $(this).data('tGrid');
expandFirstRow(grid, e.row);
}
function orders_onRowDataBound(e) {
var grid = $(this).data('tGrid');
expandFirstRow(grid, e.row);
}
function unit_onDetailViewExpand(e) {
var mstRow = e.masterRow;
var unitNumber = mstRow.cells[1].innerHTML;
derpinski = derpinski + unitNumber + ",";
}
function unit_onDetailViewCollapse(e) {
var mstRow = e.masterRow;
var unitNumber = mstRow.cells[1].innerHTML;
derpinski = derpinski.replace(unitNumber + ",", "");
}
答案 0 :(得分:0)
我发现嵌套网格无法做到这一点。
我最终在自定义类中创建了一个字符串变量,并使用了Telerik网格中的Bound机制并对网格中的html-string进行编码。这不是最漂亮的解决方案,但只要我需要它就可以工作。
这样的事情:
[GridAction]
public ActionResult SelectedUnitPeriod(int unitId, string startDate)
{
// Some stuff (just to abbreviate
unitPeriodName = ""; // Created the row as string
daystr = ""; // also with this one
rentableUnitPeriods.Add(new RentableUnitPeriod(unitPeriod.UnitId, unitPeriodName, dayStr, unitPeriod.PrimaryImg));
return View(new GridModel(rentableUnitPeriods));
}
这就是我的诀窍:)