自定义对象上一个过滤电网剑道 [英] Filtering a Kendo Grid on a custom object

查看:122
本文介绍了自定义对象上一个过滤电网剑道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剑道电网与使用自定义对象的显示模板。我实现了IComparable的允许分组和排序,但我不知道我需要做的就是筛选工作。正因为如此,当我点击过滤器按钮的列有一个空白的下拉列表,而不是通常的'包含,开头,等于'和这样的选项,通常会显示出来。我使用的 ToDataSourceResult 以操纵的结果。

模型:

 公共类LEAProgramMap
{
    公共字符串entity_program {搞定;组; }
    [UIHint(ProgramEditor)]
    公共ProgramDDL program_desc {搞定;组; }
}

在下拉菜单:

 公共类ProgramDDL:IComparable的
{
    公共短program_id {搞定;组; }
    公共字符串entity_program {搞定;组; }
    公共字符串program_desc {搞定;组; }
    公众诠释的CompareTo(obj对象)
    {
        如果(obj是ProgramDDL)
        {
            ProgramDDL转2 =(ProgramDDL)目标文件;
            返回program_desc.CompareTo(rev2.program_desc);
        }
        其他
            抛出新的ArgumentException(对象不是ProgramDDL);
    }
}

和视图:

  @model IEnumerable的< D​​atamart.Models.ViewModels.LEAProgramMap>@ {
    ViewBag.Title =CreateProgramMap;
    VAR快照=会话[snapshot_id]? Request.Params [snapshot_id];
}< H2> CreateProgramMap< / H>
@(Html.Kendo()。网格(模型)
。名称(程序)
.Columns(COLS =>
    {
        cols.Bound(p值=> p.entity_program).ClientTemplate(#= entity_program#);
        cols.Bound(p值=> p.program_desc).ClientTemplate(#= program_desc.program_desc#);
    })
.ToolBar(命令=>
    {
        commands.Save();
    })
.Editable(编辑= GT; edit.Enabled(真).Mode(GridEditMode.InCell))
.DataSource(DS => DS
            阿贾克斯()
            。型号(型号= GT;
                {
                    model.Id(p值=> p.entity_program);
                    model.Field(P => p.entity_program).Editable(假);                })
    //配置RU - >
                .Read(读=方式> read.Action(Program_Read,草案)的数据(additionalData))
                .Update(更新=方式> update.Action(Program_Update,草案)的数据(additionalData))
    //.ServerOperation(false)
                .Batch(真)
                .Events(事件=>事件
                    //.Change(\"onChange)
                    .Error(onError的)
                    )
                )
        //< - 配置RU
        .Pageable(页面=方式> page.PageSizes(新INT [] {10,25,50,100})启用(true))
        .Groupable(组=> group.Enabled(真))
        .Filterable(过滤=> filter.Enabled(真).Extra(真))
        .Sortable(排序= GT; sort.Enabled(真).SortMode(GridSortMode.SingleColumn).AllowUnsort(真))
        .Navigatable(NAV => nav.Enabled(真))
        .Resizable(调整=> resizing.Columns(真))
        .Reorderable(重排= GT; reorder.Columns(真))
            )<脚本>
功能additionalData(){
    返回{
        snapshot_id:@snapshot
    };
}功能的onError(即状态){
    如果(e.errors){
        VAR消息=发生以下错误:\\ n;        $。每个(e.errors,功能(键,值){
            如果(value.errors){
                消息+ = value.errors.join(\\ n);
            }
        });        警报(消息);
    }
}起作用的onChange(){
    VAR电网= $(#程序)的数据(kendoGrid);    grid.dataSource.read();
}
< / SCRIPT>


解决方案

不幸的是剑道UI不支持类成分/包含复杂的对象视图模型,您的视图模型需要是完全平坦的,以避免意外行为。所以,你的类应该是这样的。

 公共类LEAProgramMap
{
    公共字符串entity_program {搞定;组; }
    公共短program_id {搞定;组; }
    公共字符串entity_program {搞定;组; }
    公共字符串program_desc {搞定;组; }
}

I have a Kendo Grid with a display template that is using a custom object. I've implemented IComparable to allow grouping and sorting, but I'm not sure what I need to do to get the filtering to work. As it is, when I click the Filter button for the column it has a blank dropdown instead of the usual 'Contains, starts with, equals' and such options that would normally show. I am using the ToDataSourceResult to manipulate the results.

The model:

public class LEAProgramMap
{
    public string entity_program { get; set; }
    [UIHint("ProgramEditor")]
    public ProgramDDL program_desc { get; set; }
}

The dropdown:

public class ProgramDDL : IComparable
{
    public short program_id { get; set; }
    public string entity_program { get; set; }
    public string program_desc { get; set; }
    public int CompareTo(object obj)
    {
        if (obj is ProgramDDL)
        {
            ProgramDDL rev2 = (ProgramDDL)obj;
            return program_desc.CompareTo(rev2.program_desc);
        }
        else
            throw new ArgumentException("Object is not a ProgramDDL");
    }
}

and the view:

@model IEnumerable<Datamart.Models.ViewModels.LEAProgramMap>

@{
    ViewBag.Title = "CreateProgramMap";
    var snapshot = Session["snapshot_id"] ?? Request.Params["snapshot_id"];
}

<h2>CreateProgramMap</h2>
@(Html.Kendo().Grid(Model)
.Name("Programs")
.Columns(cols =>
    {
        cols.Bound(p => p.entity_program).ClientTemplate("#=entity_program#");
        cols.Bound(p => p.program_desc).ClientTemplate("#=program_desc.program_desc#");
    })
.ToolBar(commands =>
    {
        commands.Save();
    })
.Editable(edit => edit.Enabled(true).Mode(GridEditMode.InCell))
.DataSource(ds => ds
            .Ajax()
            .Model(model =>
                {
                    model.Id(p => p.entity_program);
                    model.Field(p => p.entity_program).Editable(false);

                })
    // Configure RU -->
                .Read(read => read.Action("Program_Read", "Draft").Data("additionalData"))
                .Update(update => update.Action("Program_Update", "Draft").Data("additionalData"))
    //.ServerOperation(false)
                .Batch(true)
                .Events(events => events
                    //.Change("onChange")
                    .Error("onError")
                    )
                )
        // <-- Configure RU
        .Pageable(page => page.PageSizes(new int[] { 10, 25, 50, 100 }).Enabled(true))
        .Groupable(group => group.Enabled(true))
        .Filterable(filter => filter.Enabled(true).Extra(true))
        .Sortable(sort => sort.Enabled(true).SortMode(GridSortMode.SingleColumn).AllowUnsort(true))
        .Navigatable(nav => nav.Enabled(true))
        .Resizable(resizing => resizing.Columns(true))
        .Reorderable(reorder => reorder.Columns(true))
            )

<script>
function additionalData() {
    return {
        snapshot_id: "@snapshot"
    };
}

function onError(e, status) {
    if (e.errors) {
        var message = "The following errors have occurred:\n";

        $.each(e.errors, function (key, value) {
            if (value.errors) {
                message += value.errors.join("\n");
            }
        });

        alert(message);
    }
}

function onChange() {
    var grid = $("#Programs").data("kendoGrid");

    grid.dataSource.read();
}
</script>

解决方案

Unfortunately Kendo UI doesn't support Class Composition / View Models containing complex objects, your View Models need to be completely flat to avoid unexpected behaviour. So your class should look like this.

public class LEAProgramMap
{
    public string entity_program { get; set; }
    public short program_id { get; set; }
    public string entity_program { get; set; }
    public string program_desc { get; set; }
}

这篇关于自定义对象上一个过滤电网剑道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆