asp.net – 在telerik网格的列中使用控件

在asp.net mvc页面im使用telerik网格看起来像这样
<div>
    @(Html.Kendo().Grid<Project.Models.Bench>
        ()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.name).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
            columns.Bound(p => p.seatsCount).Filterable(ftb => ftb.Cell(cell => cell.Operator("gte")));
            columns.Bound(p => p.bookedSeats).Filterable(ftb => ftb.Cell(cell => cell.Operator("gte")));
        })

.Pageable()
.sortable()
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
            //.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
    //.ServerOperation(true)
.Read(read => read.Action("GetBenches","home"))
)
    )
</div>

这是我的Bench课程:

public class Bench
{
    public int id { get; set; }
    public string name { get; set; }
    public bool bookable { get; set; }
    public int zone { get; set; }
    public int seatsCount { get; set; }
    public string area { get; set; }
    public int bookedSeats { get; set; }
    public int freeSeats { get; set; }
}

和HomeController上的GetBenches方法

public async Task<ActionResult> GetBenches([DataSourceRequest] DataSourceRequest request)
    {
        BenchesService bService = new BenchesService();
        List<Bench> obj = await bService.getBenches();


        return Json(obj.Select(s => new Bench
        {
            id = s.id,bookable = s.bookable,name = s.name,seatsCount = s.seatsCount,zone = s.zone,freeSeats = s.freeSeats,area = s.area,bookedSeats = s.bookedSeats

        }).distinct().ToDataSourceResult(request),JsonRequestBehavior.AllowGet);
    }

我想知道如果我可以添加一个.ClientTemplate到其中一列,如果我可以在单元格中添加一个控件this type(“Benefit components”列中的一个)

解决方法

嗯,你可以从这样开始:
@(Html.Kendo().Grid<Project.Models.Bench>
    ()
    .Name("grid")
    .Columns(columns =>
    {
     columns.Bound(p => p.name).Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
     columns.Bound(p => p.Variance).Title("Booked")
         .ClientTemplate(Html.Kendo().Sparkline()
                        .Name("booked_#=name#"")
                        .Type(SparklineType.Column)
                        .Tooltip(tooltip => tooltip.Format("{0} booked"))                        
                            .DataSource(
                        .DataSource(ds => ds.Ajax()
                          .Read(read => read.Action("Read","MyController",new { myId = Model.MyID })
                           )
                        .ToClientTemplate()
                        .ToHtmlString()
                       );

    })
    ...

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....