asp.net - 在 Telerik 网格的列内使用控件

标签 asp.net asp.net-mvc telerik telerik-grid

在 asp.net mvc 页面中,我使用了如下所示的 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>

这是我的长凳课:
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);
    }

如果我可以添加 this type 的控件,我想知道是否将 .ClientTemplate 添加到其中一列单元格内部(“福利组件”列中的那个)

最佳答案

好吧,你可以从这样的事情开始:

@(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()
                       );

    })
    ...

关于asp.net - 在 Telerik 网格的列内使用控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32380699/

相关文章:

javascript - 内容安全政策

javascript - 如何将 JavaScript 变量传递给服务器端方法

html - 无法加载所有资源 - 错误 500

asp.net - Telerik RadTreeView 控件的添加/编辑/删除按钮

javascript - 扩展剑道多选并使用 MVVM

c# - 如何在 ASP.NET 应用程序运行的整个过程中保持 SqlConnection 处于打开状态?

asp.net - 使用 Base Controller 获取 Common ViewData

jquery - Blueimp Jquery-File-Upload 通过 IE 9 在 MVC Controller 中提交空文件

asp.net-mvc - T4MVC 在控件库中使用扩展方法

javascript - 网格初始化后的 Kendo 网格事件处理