Grid Grouping - Null vs Empty String

3 posts, 0 answers
  1. Scott
    Scott avatar
    5 posts
    Member since:
    Aug 2012

    Posted 21 Jul Link to this post

    We noticed that when grouping on columns that sometimes have a null and sometimes have an empty string, it will create two different groupings.

    I tried to update the ViewModel in MVC so the property always returns an empty string:

    public class SampleViewModel
    {     
        private string _name;         
       
        [StringLength(50)]
        public string Name     
        {         
            get { return _name ?? string.Empty; }         
            set { _name= value; }     
        }
    }

    That still produces two different groupings.

    How can I get the grid to group these the same way?

  2. Stefan
    Admin
    Stefan avatar
    272 posts

    Posted 25 Jul Link to this post

    Hello Scott,

    The grouping in the Grid is by matching values. Since null and empty string are different values, it is by design to have different groups.

    I can suggest checking if the null values are correctly converted to an empty string in the Grid data. If client-side grouping is performed, and the data cannot be converted server-side, it is possible to do that client-side, in the schema.parse function:

    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.parse

    You can verify if the data is properly converted server-side by inspecting the server-response.

    If you notice an erroneous behavior in Kendo UI and further assistance is needed, please send a runnable example, so we can investigate it.

    Regards,
    Stefan
    Telerik by Progress
     
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
  3. Kendo UI is VS 2017 Ready
  4. Scott
    Scott avatar
    5 posts
    Member since:
    Aug 2012

    Posted 26 Jul Link to this post

    I was able to correct the issue.  The ViewModel rules were too late in the process.  ToDataSourceResult had already done the grouping.

    So I added a line before it and this works:

    var results = from s in Sample select new SampleViewModel { Name = s.Name ?? string.Empty };                 
    return Json(results.ToDataSourceResult(request));

Back to Top