【问题标题】:use a control inside a column on a telerik grid在 Telerik 网格上的列内使用控件
【发布时间】:2015-11-29 14:06:13
【问题描述】:

在 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 添加到其中一列中

【问题讨论】:

  • 是的,但仍然有一点困难:\ 仍然是 q 位新手。我想要的是替换我拥有的最后 2 列,其中这 2 列的值将用于创建迷你图(总座位数与预订座位数)
  • 有没有机会给我更多的帮助?

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


【解决方案1】:

嗯,你可以从这样的开始:

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

    })
    ...

【讨论】:

  • 这是您的数据源。有几种连接数据的方法。你也可以从你的模型中获取它。
  • 所以如果我想使用我班级长凳的 2 个字段,在这种情况下,bookedSeats 和 freeSeats 都是整数,那么最好的方法是什么?
  • 如果你能给出一个更完整的例子,我将不胜感激:)
  • 我本身并没有使用过该控件,但我发现使用 Kendo 小部件的最佳方法是让一个最小的示例工作,然后添加功能并寻找特定问题的答案,例如数据源、事件、轴等
  • 我真的需要这个来工作,这是我工作中的一个亮点。感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多