This is a migrated thread and some comments may be shown as answers.

Kendo Load On Demand Treelist showing duplicate records on server side filtering

2 Answers 153 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 25 Oct 2017, 01:26 PM

I am using Kendo Treelist ie: Load on Demand in our application. I'm using the 2017.1.223 version for kendo. Applied server side filtering for my treelist.

When I try to apply filter to my columns, the result shows me duplicate records. Posting my code below:

Controller method
------------------------------------------------
public async Task<JsonResult> GetAssetTreeListBasedOnPermissions([DataSourceRequest] DataSourceRequest request, AssetColumnFilters assetcolumnFilters,int? id)
        {
            try
            {
                string searchExpression = string.Empty;
                AssetColumnFilters columnFilters = new AssetColumnFilters();

                if (!string.IsNullOrEmpty(assetcolumnFilters.AssetId))
                {
                    var assetIds = assetcolumnFilters.AssetId.ToString().Split(',');
                    var i = 0;
                    var assetString = "";
                    foreach (var assetId in assetIds)
                    {
                        if (i == 0)
                        {
                            assetString += " (A.AssetId=" + assetId + ") ";
                        }
                        else if (i > 0)
                        {
                            assetString += " OR (A.AssetId=" + assetId + ") ";
                        }
                        i++;
                    }

                    searchExpression = assetString;

                }

             
               string searchExp = searchExpression;
              
                AssetFiltersModel filters = new AssetFiltersModel();

                long? companyId = SiteSession.CurrentSession.CompanyId;
                long userId = SiteSession.CurrentSession.UserId;

                //FIRST TIME LOAD
                if (id==null && request.Filters.Count==0)
                searchExp = string.IsNullOrEmpty(searchExp) ? " (SA.ParentAssetId=" + 0 + " AND A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ")" : "(SA.ParentAssetId=" + 0 + " AND A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ") and " + searchExp;
                
else if(id==null&& request.Filters.Count>0)
                    searchExp = string.IsNullOrEmpty(searchExp) ? " (A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ")" : "(A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ") and " + searchExp;
                else
                searchExp = string.IsNullOrEmpty(searchExp) ? " (SA.ParentAssetId=" + id + " AND A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ")" : "(SA.ParentAssetId=" + id + " AND A.CompanyId=" + SiteSession.CurrentSession.CompanyId + ") and " + searchExp;
                
            
               

                filters.SearchExpression = searchExp;
                filters.SortExpression = (request.Sorts.Count > 0) ? request.Sorts.FirstOrDefault().Member : string.Empty;
                filters.SortDirection = (request.Sorts.Count > 0) ? (request.Sorts.FirstOrDefault().SortDirection == ListSortDirection.Ascending ? " asc" : " Desc") : string.Empty;
                filters.StartIndex = Helper.GetCurrentPage(request.Page, request.PageSize);
                filters.PageSize = request.PageSize;
                filters.UserId = userId;
                var assetGridList = await aladdinRestClient.PostAsync<AssetFiltersModel, AssetListModel>(Constant.GETASSETLISTBASEDONUSER, filters, false);
             
                var list= assetGridList.AssetList.AsQueryable();

                var result = list
               .Select(e => new AssetModel
                  {
                      AssetId = e.AssetId,
                      ParentAssetId = e.ParentAssetId,
                   AssetName = e.AssetName,
                   AssetIdEncrypt = e.AssetIdEncrypt,
                   hasChildren = e.IsParent == 1 ? true : false,
                   AssetNo = e.AssetNo,
                   Model = e.Model,
                   SerialNumber = e.SerialNumber,
                   Category1Name = e.Category1Name,
                   Category2Name = e.Category2Name,
                   Category3Name = e.Category3Name,
                   Category4Name = e.Category4Name,
                   LocationLevel1Name = e.LocationLevel1Name,
                   LocationLevel2Name = e.LocationLevel2Name,
                   LocationLevel3Name = e.LocationLevel3Name,
                   LocationLevel4Name = e.LocationLevel4Name,                  
                   StatusName = e.StatusName,
                   IsAttachmentsExist = e.IsAttachmentsExist
               }).ToTreeDataSourceResult(request,
                   e => e.AssetId,
                   e => e.ParentAssetId
                  
                    
                 );
            

                var jsonResult = Json(result, JsonRequestBehavior.AllowGet);
                jsonResult.MaxJsonLength = Int32.MaxValue;
                return jsonResult;
               


            

            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
View 
---------------------------------------------------------------------------
 @(Html.Kendo().TreeList<AssetModel>()
               .Name("assetTreeList")
               .Columns(columns =>
               {
                   columns.Add().Field(a => a.AssetId).Hidden(true);
                   columns.Add().Field(a => a.AssetIdEncrypt).Hidden(true);
                   //.Template("#if(IsAttachmentsExist == true) {#" + "<a class='k-button' href='javascript:void(0);' onclick='EditAsset(#:AssetId#,true);'><span class='k-i-attachment-45 k-i-clip-45'></span>#= AssetName# </a>" + "#}else {#" + "<a class='inline-link' href='javascript:void(0);' onclick='EditAsset(#:AssetId#,true);' style='margin-right:5px;'>#= AssetName# </a>" + "#} #").Width(290);
                   columns.Add().Field(a => a.AssetName).TemplateId("attachment-template").Width(290)/*.HeaderTemplateId("expandAll-template")*/;
                   columns.Add().Field(a => a.AssetNo).Title(AssetDetailResource.AssetNumber).Width(250).Hidden((bool)ViewData["AssetNumber"]);
                   columns.Add().Field(a => a.Model).Title(AssetDetailResource.Model).Width(120).Hidden((bool)ViewData["Model"]);
                   columns.Add().Field(a => a.SerialNumber).Title(AssetDetailResource.SerialNumber).Width(150).Hidden((bool)ViewData["SerialNumber"]);
                   columns.Add().Field(a => a.LocationLevel1Name).Title(AssetDetailResource.LocationLevel1Name).Width(180).Hidden((bool)ViewData["LocationLevel1"]);
                   columns.Add().Field(a => a.LocationLevel2Name).Title(AssetDetailResource.LocationLevel2Name).Width(180).Hidden((bool)ViewData["LocationLevel2"]);
                   columns.Add().Field(a => a.LocationLevel3Name).Title(AssetDetailResource.LocationLevel3Name).Width(180).Hidden((bool)ViewData["LocationLevel3"]);
                   columns.Add().Field(a => a.LocationLevel4Name).Title(AssetDetailResource.LocationLevel4Name).Width(180).Hidden((bool)ViewData["LocationLevel4"]);
                   columns.Add().Field(a => a.Category1Name).Title(AssetDetailResource.Category1).Width(180).Hidden((bool)ViewData["CategoryLevel1"]);
                   columns.Add().Field(a => a.Category2Name).Title(AssetDetailResource.Category2).Width(180).Hidden((bool)ViewData["CategoryLevel2"]);
                   columns.Add().Field(a => a.Category3Name).Title(AssetDetailResource.Category3).Width(180).Hidden((bool)ViewData["CategoryLevel3"]);
                   columns.Add().Field(a => a.Category4Name).Title(AssetDetailResource.Category4).Width(180).Hidden((bool)ViewData["CategoryLevel4"]);
                   columns.Add().Field(a => a.StatusName).Title(@SGE.Aladdin.Resources.SGEAdmin.AdminResources.Status).Width(120).Hidden((bool)ViewData["Status"]);
                   //if (IsAdd)
                   //{
                   //    columns.Add().Template("<a href='javascript:void(0);' onclick='CloneAsset(#:AssetId#);' class='duplicate-ico' title='" + string.Format(CommonResources.CloneTooltip, CommonResources.Assets) + "'>" + "</a>").Title(CommonResources.Clone).Width(50);
                   //}
                   if (IsDelete)
                   {
                       columns.Add().Template("<a href='javascript:void(0);' onclick='DeleteAsset(#:AssetId#);' class='delete-ico' title='" + string.Format(CommonResources.DeleteTooltip, CommonResources.Assets) + "'>" + "</a>").Title(CommonResources.Delete).Width(50);
                   }

               })
               .Sortable()
               .Events(ev => ev.DataBound("onTreeListDataBound"))
               .Events(ev => ev.FilterMenuInit("filterMenuInit"))
               .DataSource(dataSource => dataSource
                .Read(read => read.Action("GetAssetTreeListBasedOnPermissions", "Asset"))
                .ServerOperation(true)                
                .Model(m =>
                {
                    m.Id(e => e.AssetId);
                    m.ParentId(e => e.ParentAssetId);
                    m.Field(e => e.AssetName);
                })
                )              
                .Filterable(true)
                .Reorderable(true)
                .Resizable(true)
                .Scrollable(true)
                .Sortable(true)

                )

 In the above code, when a column filter is applied, I am getting the entire data in 'list' variable. When this list of data is converted to treedatasourceresult, the filter will get applied to the data. In the result variable, I can see the filtered results with duplicates. Please see the attached image. Based on the filter, the result should return  asset 05, ASSET 01=>ASSET 008. But now its showing as in the attached image, which is incorrect. Could you please help me? Your help will be much appreciated.

2 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 27 Oct 2017, 10:15 AM
Hello,

There was a dublication problem when load on demand was used in the older version but it is now resolved. Please update to the latest kendo version and check whether the issue reproduces. If it does I suggest opening a formal support ticket and attaching a small runnable sample there.

Regards,
Angel Petrov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
James
Top achievements
Rank 1
answered on 01 Nov 2017, 05:19 AM

Hello Angel,

Thanks for the response. I will update to the new version and will get back to you.

Regards

Binta

 

Tags
TreeList
Asked by
James
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
James
Top achievements
Rank 1
Share this question
or