Kendo UI Grid for MVC GroupBy扩展无法按预期工作

时间:2019-05-24 07:43:59

标签: c# asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc

我有这些代码行

if (descriptors != null && descriptors.Groups.Any() )
{
   source = source.GroupBy( descriptors.Groups );
}

源是MyBigModel类型的未分组数据的列表

我的大模特看起来像这样

public class MyBigModel: MyBigBaseViewModel, IDynamicParameterListItemViewModel
{
    #region Properties
    public int ID { get; set; }
    public int UserID { get; set; }

    public int TrainingID { get; set; }

    public string TrainingName { get; set; }

    public string TrainingDescription { get; set; }

    public string TrainingType { get; set; }

    public string TimeZone { get; set; }
    public int? TimeZoneID { get; set; }

    public DateTime? StartDate { get; set; }

    public DateTime? EndDate { get; set; }

    public int? Duration { get; set; }

    public decimal? MaxP { get; set; }

    public decimal? AverageP { get; set; }

    public string UserDisplayName { get; set; }

    public string LoginName { get; set; }

    public string UserFirstName { get; set; }

    public string UserLastName { get; set; }

    public string UserEmail { get; set; }

    //public string BookingType { get; set; }

    //public string BookingStatus { get; set; }

    public DateTime? BookingDate { get; set; }

    public DateTime? CancellationDate { get; set; }

    public string UserBookingModifiedBy { get; set; }

    public string UserBookingModifiedByType { get; set; }

    public string CompanyName { get; set; }

    public string ExternalCustomerNumber { get; set; }

    public string CustomerNumber { get; set; }

    public string ExternalCompanyNumber { get; set; }

    public string CompanyNumber { get; set; }

    public int? TrainingActivities { get; set; }

    public decimal? NetPrice { set; get; }

    public string NetPriceCurrency { set; get; }

    public int? CancellationPolicyDays { get; set; }

    public string ArticleNumber { set; get; }

    public string CostCenter { get; set; }

    public string PersonnelNumber { get; set; }

    public string OrderNumber { get; set; }

    public string InvoiceNumber { get; set; }
    public int TrainingSignatureID { get; set; }

    public int BookType { get; set; }
    public int BookStatus { get; set; }

    public string ParsedTrainingUserGroupsNames { get; set; }
    public string ParsedTrainingUserGroupsIDs { get; set; }

    public string DynamicParametersTrainings { get; set; }

    public string DynamicParametersUsers { get; set; }


    public string MatrixSignature
    {
        get
        {
            Dictionary<string, string> matrixDimensions = new Dictionary<string, string>();
            foreach (var dimension in MatrixSignatureDimensions)
            {
                List<MatrixDimensionLayerTreeViewModel> allConnectedLayers = dimension.Layers
                                                                                      .Flatten(l => l.Layers)
                                                                                      .Where(l => l.IsConnected)
                                                                                      .ToList();

                IEnumerable<string> connectedLayerNames = allConnectedLayers
                                                                            .Select(p => p.BaseLayer.Name)
                                                                            .OrderBy(p => p);

                if (allConnectedLayers.Any())
                {
                    matrixDimensions[dimension.BaseDimension.Name] = connectedLayerNames.StringJoin();
                }
            }
            return matrixDimensions.Select(x => string.Format("{0}: ({1})", x.Key, x.Value)).ToList().StringJoin(separator: ", ");
        }
    }

    public string BookingType
    {
        get
        {
            return
               ((TrainingBookingUserType)this.BookType).ToLabelTranslationTermString().TranslateForManagement();
        }
    }

    public string BookingStatus
    {
        get
        {
            return
                 ((TrainingBookingStatus)this.BookStatus).ToLabelTranslationTermString().TranslateForManagement();
        }
    }

    public string TrainingTypeID
    {
        get
        {
            return this.TrainingType.TranslateForManagement();
        }
    }
    public decimal? MaxPoints
    {
        get
        {
            return this.MaxP.HasValue ? Math.Round(this.MaxP.Value, 2) : (decimal?)null;
        }
    }
    public decimal? AveragePoints
    {
        get
        {
            return this.AverageP.HasValue ? Math.Round(this.AverageP.Value, 2) : (decimal?)null;
        }
    }

    public DateTime? TrainingStartDate
    {
        get
        {
            return this.StartDate.ToUserLocalTime(this.TimeZoneID);
        }
    }

    public DateTime? TrainingEndDate
    {
        get
        {
            return this.EndDate.ToUserLocalTime(this.TimeZoneID);
        }
    }

    public string DynamicParatemeterValues
    {
        get
        {
            if (string.IsNullOrEmpty(this.DynamicParametersTrainings) && string.IsNullOrEmpty(this.DynamicParametersUsers))
            {
                return string.Empty;
            }
            else
            {
                if (!string.IsNullOrEmpty(this.DynamicParametersTrainings) && !string.IsNullOrEmpty(this.DynamicParametersUsers))
                {
                    return string.Concat(this.DynamicParametersTrainings, this.DynamicParametersUsers);
                }
                else
                {
                    if (!string.IsNullOrEmpty(this.DynamicParametersTrainings))
                    {
                        return this.DynamicParametersTrainings;
                    }
                    else
                    {
                        return this.DynamicParametersUsers;
                    }
                }
            }
        }
    }

    public Dictionary<string, string> CustomFields { set; get; }

    //public Dictionary<string, string> ParsedCustomFields
    //{
    //    set { }
    //    get
    //    {
    //        return !String.IsNullOrEmpty(this.DynamicParatemeterValues) ? this.ExtractCustomFields(this.DynamicParatemeterValues) : null;
    //    }
    //}

    public string ParsedUserGroupsIDs
    {
        get
        {
            return this.ParsedTrainingUserGroupsIDs;
        }
    }

    public List<int> ResourceTrainingUserGroupIDs
    {
        get
        {
            return !String.IsNullOrEmpty(this.ParsedUserGroupsIDs) ? this.ParsedUserGroupsIDs.Split(',').Select(int.Parse).ToList() : null;
        }
    }

    public string ParsedUserGroupNames
    {
        get
        {
            return this.ParsedTrainingUserGroupsNames;
        }
    }

    public List<string> TrainingResourceUserGroups
    {
        set { }
        get
        {
            return !String.IsNullOrEmpty(this.ParsedUserGroupNames) ? this.ParsedUserGroupNames.Split(',').ToList() : null;
        }
    }

    public Dictionary<string, string> ParsedCustomFields
    {
        set { }
        get
        {
            return !String.IsNullOrEmpty(this.DynamicParatemeterValues) ? this.ExtractCustomFields(this.DynamicParatemeterValues) : null;
        }
    }

    // public Dictionary<string, string> CustomFields { get; set; }
    #endregion

    #region Matrix
    private List<MatrixDimensionTreeViewModel> MatrixSignatureDimensions
    {
        get
        {
            return MatrixCacheHelper.Current.GetSignatureDimensions(this.TrainingSignatureID, null, Modules.Trainings);
        }
    }
    #endregion

    #region Methods
    public Dictionary<string, string> ExtractCustomFields(string parameters)
    {
        if (string.IsNullOrEmpty(parameters))
        {
            return null;
        }
        Dictionary<string, string> dict = new Dictionary<string, string>();
        List<string> list1 = parameters.Split(new string[] { ",__NextParam_" }, StringSplitOptions.RemoveEmptyEntries).ToList();
        foreach (var str in list1)
        {
            string[] arr = str.Split(new string[] { "Val:" }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length != 0)
            {
                dict.Add(arr[0].Trim(), arr[1]);
            }
        }

        return dict;
    }
    #endregion

    #region Constructor
    public MyBigModel()
        : base()
    {
        CustomFields = new Dictionary<string, string>();
    }
    #endregion
}

descriptors.Groups包含2个项目。 TrainingActivitiesTrainingName具有确切的顺序,类型为int?string

第一个分组级别正常,但是在第二个分组级别中,第一个分组之后所有子组均为空

enter image description here

根据数据,在第二组下,应该有一个包含一个项目的TrainingName子组。

手表是这样的

未分组的数据:

enter image description here

分组数据: enter image description here

GroupBy是IQuerable的Kendo扩展方法,似乎不能正常工作。有类似情况吗?任何想法我的代码可能出什么问题了吗?

0 个答案:

没有答案