应用过滤器时,Kendo TreeList重复节点

时间:2015-02-25 19:14:54

标签: asp.net-mvc-4 kendo-ui

我创建了一个包含组织报告结构的目录列表。

除了过滤外,一切正常。

当我搜索一个唯一的值,例如Employee Badge Number时,TreeList会正确过滤所有显示的父节点。

但是当我在不同的节点级别(例如部门名称)中搜索具有相同值的字段时,我在TreeList上获得了重复的条目。

Directory.cshtml

   <script id="photo-template" type="text/x-kendo-template">
         #if ( ProfilePictureId == null ){#
        <img src="/Areas/GDirectory/Contents/images/Avatar.jpg" class="profile-photo" />
        #} else {#
        <img src="/Areas/GDirectory/Contents/images/Avatar.jpg" class="profile-photo" data-url="@Url.Action("GetProfilePicture", "Directory")/?picid=${ProfilePictureId}" />
            #}#

        <div class='employee-name'>#: FirstName #</div>
    </script>


    @(Html.Kendo().TreeList<Gnet.Areas.GDirectory.ViewModels.DirectoryProfileVM>()
            .Name("DirectoryList")
            .Columns(columns =>
            {
                columns.Add().Field(p => p.FirstName).Title("First Name").Width(260).TemplateId("photo-template");
                columns.Add().Field(p => p.LastName).Title("Last Name").Width(130);
                columns.Add().Field(p => p.Title).Width(180).Template("#= (Title == null)? 'N/A' : Title #");
                columns.Add().Field(p => p.DepartmentName).Title("Department").Width(180).Template("#= (DepartmentName == null)? 'N/A' : DepartmentName #");
                columns.Add().Field(p => p.CostCenterName).Title("Cost Center").Width(100).Template("#= (CostCenterName == null)? 'N/A' : CostCenterName #");            
                columns.Add().Field(p => p.BadgeNumber).Title("Badge #").Width(95).Template("#= (BadgeNumber == null)? 'N/A' : BadgeNumber #");
                columns.Add().Field(p => p.SapNumber).Title("SAP #").Width(95).Template("#= (SapNumber == null)? 'N/A' : SapNumber #");
                columns.Add().Field(p => p.SiteName).Title("Site").Width(110).Template("#= (SiteName == null)? 'N/A' : SiteName #");
                columns.Add().Field(p => p.SeatNumber).Title("Seat #").Width(100).Template("#= (SeatNumber == null)? 'N/A' : SeatNumber #");            
                columns.Add().Field(p => p.Extension).Title("Ext").Width(80).Format("{0:#}").Template("#= (Extension == null)? 'N/A' : Extension #");
                columns.Add().Field(p => p.Email).Width(80).Template("<button type='button' onclick=\"location.href='mailto:#=Email#'\">Send</button>").Filterable(false);            
                columns.Add().Command(c =>
                    {
                        c.Custom().Name("Assets").Click("showAssetModal");
                        c.Custom().Name("EditProfile").Text("Edit").Click("showEditProfileForm");
                        c.Custom().Name("Delete").Click("showDeleteProfileModal");
                    }).Width(100);
            })        
            .Toolbar(tools => tools.Excel())
            .Excel(excel => excel
                .FileName("GDirectory Contact List.xlsx")
                .Filterable(true)
                .ProxyURL(Url.Action("ContactListExport", "Directory")))
            .Sortable(true)
            .Filterable(f => f.Extra(false))        
            .Scrollable(true)
            .Events(e => e.DataBound("onDirectoryBound"))
            .DataSource(dataSource => dataSource
                        .Read(read => read.Action("GetAllDirectoryList", "Directory"))                                                           
                        .ServerOperation(false)
                        .Model(m =>
                        {
                            m.Id(t => t.Id);
                            m.ParentId(t => t.ReportToId);
                            m.Field(t => t.FirstName);
                            //m.Field(t => t.LastName);
                            //m.Field(t => t.DepartmentId);
                            //m.Field(t => t.DepartmentName);
                            //m.Field(t => t.CostCenterName);
                            //m.Field(t => t.Title);
                            //m.Field(t => t.BadgeNumber);
                            //m.Field(t => t.SapNumber);
                            //m.Field(t => t.SiteName);
                            //m.Field(t => t.SeatNumber);
                            //m.Field(t => t.Email);
                            //m.Field(t => t.Extension);
                            m.Field(t => t.ReportToId);
                        }
                )
            )
            .Height(600)
    )

视图模型

   public class DirectoryProfileVM
        {      

            public int Id { get; set; } // Id
            public int? UserId { get; set; } // UserId
            public int? ProfilePictureId { get; set; } // ProfilePictureId
            public int? DepartmentId { get; set; } // DepartmentId
            public int? SiteId { get; set; } // SiteId
            [DisplayName("First Name")]
            public string FirstName { get; set; } // FirstName
            [DisplayName("Last Name")]
            public string LastName { get; set; } // LastName
            [DisplayName("Badge #")]
            public string BadgeNumber { get; set; } // BadgeNumber
            [DisplayName("SAP #")]
            public string SapNumber { get; set; } // SAPNumber
            public string Email { get; set; } // Email
            public string Extension { get; set; } // Extension
            public string Title { get; set; } // Title
            [DisplayName("Site")]
            public string SiteName { get; set; } // SiteName
            [DisplayName("Seat #")]
            public string SeatNumber { get; set; } // SeatNumber

            [UIHint("ReportToList")]
            public int? ReportToId { get; set; } // ReportToId
            [DisplayName("Reports To")]
            public string ReportToName { get; set; } // ReportToName
            public DateTime? CreateDate { get; set; } // CreateDate
            public DateTime? LastUpdateDate { get; set; } // LastUpdateDate
            public DateTime? DeleteDate { get; set; } // DeleteDate
            public string Mime { get; set; } // MIME
            public byte[] RawFile { get; set; } // RawFile
            [DisplayName("Department")]
            public string DepartmentName { get; set; } // DepartmentName
            public string DepartmentCode { get; set; } // DepartmentCode
            public int? ParentGroupId { get; set; } // ParentGroupId
            [DisplayName("Parent Group")]
            public string ParentGroup { get; set; } // ParentGroup
            [DisplayName("User Name")]
            public string UserName { get; set; } // UserName               
            public int? CostCenterId { get; set; } // CostCenterId
            [DisplayName("Cost Center")]
            public string CostCenterName { get; set; } // CostCenterName

            public bool hasChildren { get; set; }
    }

控制器

  public JsonResult GetAllDirectoryList([DataSourceRequest] DataSourceRequest request)
        {
            Mapper.CreateMap<VwGdProfileDetail, DirectoryProfileVM>();
            DateTime now = DateTime.Now;

            var result = ctx.VwGdProfileDetails.Where(t => t.DeleteDate > now).AsEnumerable().Select(t => Mapper.Map<VwGdProfileDetail, DirectoryProfileVM>(t)).ToTreeDataSourceResult(request,
                e => e.Id,
                e => e.ReportToId,
                e => new DirectoryProfileVM
                {
                    Id = e.Id,
                    ReportToId = e.ReportToId,
                    ProfilePictureId = e.ProfilePictureId,
                    FirstName = e.FirstName,
                    LastName = e.LastName,
                    BadgeNumber = e.BadgeNumber,
                    SapNumber = e.SapNumber,
                    SiteName = e.SiteName,
                    SeatNumber = e.SeatNumber,
                    DepartmentId = e.DepartmentId,
                    DepartmentName = e.DepartmentName,
                    CostCenterName = e.CostCenterName,
                    Title = e.Title,
                    Email = e.Email,
                    Extension = e.Extension,
                    hasChildren = ctx.VwGdProfileDetails.Where(t=>t.ReportToId == e.Id).Any()
                });

            return Json(result, JsonRequestBehavior.AllowGet);
        }

由于我没有足够的声望点发布图片,我将尝试使用文本演示行为。

过滤前

名称部门徽章

John Logistic 12345

- 保罗物流51234

- Bobby Enginerring 54521


在Department =“Logistic”上应用过滤器后

名称部门徽章

John Logistic 12345

- 保罗物流51234

- 保罗物流51234

John Logistic 12345

- 保罗物流51234

- Paul Logistic 51234

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,好像这是来自Kendo Treelist过滤器的错误。我的解决方案是手动删除重复的行

    var seen = {};

    $('#DirectoryList .k-grid-content tr').each(function () {
        var id = $(this).data('uid');

        if (seen[id])
            $(this).remove();
        else
            seen[id] = true;
    });