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

Sorting Numeric Column with Null values

8 Answers 389 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 01 Mar 2013, 07:20 PM
I have a grid with 'Age' as one of the columns.
schema: {
    model: {
        fields: {
            Age: {
                type: "number"
            }
        }
    }
}
By default the null values showed as 'null' so I modified the template use a non-breaking space instead.
if (field == "Age")
    columns[currentCol].template = "#= (Age == null) ? ' ' : Age #";
The problem is, no matter if there is no template, or I use a template with ' ' (single space) or nbsp, sorting treats null and 0 the same so the resulting sorted column can display as [null, null, 0, null, 0, 0, 1, 2, 3, 4...].  I would think null should appear before 0.

Is there a way to enforce a sort order of [null/undefined, 0, 1, 2, 3...] ?

Possible Bug: Internet Explorer and Chrome sort the values differently. Being an age colum, the numbers are grouped correctly but withing the 'Age = 15 rows' the order is not the same.  The orders are reversed from each other as far as I can tell with my limited testing.

8 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 05 Mar 2013, 09:12 AM
Hi Jason,

Could you please verify that you are using latest version (Q3 2012 SP1 or Q1 2013 BETA) of KendoUI?

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jason
Top achievements
Rank 1
answered on 05 Mar 2013, 05:31 PM
I am currently using v2012.1.515.  I'll use the Telerik Control Panel and get the latest Kendo UI Web Package and let you know if it works.
0
Jason
Top achievements
Rank 1
answered on 05 Mar 2013, 11:01 PM
Thank you that does fix the issue with nulls and zeros being treated differently.

IE and Chrome still end up with a different sort order in a given age group though.
I sort 460 records by Age and the age 67 group has 7 records.
In IE the records are in this order (92, 95, 96, 115, 116, 454, 525).  Order is not always descending
In Chrome they are in this order (96, 92, 454, 116, 115, 95, 525).

And upgrading either the kendo controls or the jquery.min.js (which was in the kendo js folder) has caused/exposed other bugs on my site :( 
0
Rosen
Telerik team
answered on 06 Mar 2013, 08:35 AM
Hi Jason,

I'm not sure I understood your scenario. Is there an explicit ordering set on the field which is not sorted? Could you please provide a small sample which demonstrates this behavior.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jason
Top achievements
Rank 1
answered on 06 Mar 2013, 05:18 PM
I have attached screen shots from IE9 and Chrome.  There are 7 records with Age = 30, they are not in the same order in both images.

When the grid is populated the data set comes from a stored procedure that sorts on intReportID which is a hidden column in the grid.  The grid doesn't know about that sort order (it is not specified in the grid set up).

The grid allows sort on a single column so the other columns sorting is not specified.  I would expect the functionality to be the same in either browser and our end users will probably notice the discrepancy.  If they are printing out report results they would expect the records to be in the same order no matter what browser they use.
0
Rosen
Telerik team
answered on 07 Mar 2013, 07:26 AM
Hello Jason,

I'm afraid that this is expected. As the records are sorted during the grouping process, their initial order may change. Therefore, to ensure that ordering is persisted you should explicitly set a sort descriptor over the appropriate field. For example:

dataSource: {
     group: { field: "Age" },
     sort: { field: "intReportID", dir: "asc" }
}

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jason
Top achievements
Rank 1
answered on 08 Mar 2013, 07:00 PM
So is that the underlying browser causing the issue or Kendo's browser specific code?

I am not using the group option.  I am only using one single column sort.  The original grid has no sort applied and then I click Age to sort 'asc.'

So without allowing for multi-column sorting, is there no way to get the same results in each browser?
0
Rosen
Telerik team
answered on 11 Mar 2013, 08:38 AM
Hi Jason,

Indeed, the differences in the ordering is caused by the fact that Chrome does not use a stable sort algorithm for arrays bigger then 10 elements. In your scenario in order to ensure the same ordering of the elements you should consider using server-side data processing (sorting, paging etc.). This way you will be able skip the built-in client processing and to construct the data in the desired order.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Jason
Top achievements
Rank 1
Share this question
or