Sort columns doesn't work if fields are null

RESOLVED FIXED

Status

Calendar
Sunbird Only
RESOLVED FIXED
14 years ago
12 years ago

People

(Reporter: gekacheka, Assigned: Mostafa Hosseini)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040514
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040514

Sort columns doesn't seem to work if some events have null field value, but does
work if all have a value.



Reproducible: Always
Steps to Reproduce:
1. Create several events with "test" in the title
2. Create events without setting the title
3. sort today's events by title (click title column header)
4. type "test" in the "contains" field
5. sort today's events by title.

Actual Results:  
When the events with null title were included, sort did not work.
When only events with "test" in the title were included, sort did work.

Expected Results:  
null title should be treated as empty string.

Problem may be because:
   "" < "A" --> true
   null < "A" --> false
Fix may be in unifinder function sortEvents, wrap EventA.title and
EventA.location with nullToEmpty(...) where nullToEmpty is
function nullToEmpty(string) { 
  return string == null? "" : string;
}
(Reporter)

Comment 1

14 years ago
Created attachment 150501 [details] [diff] [review]
unifinder.js, unifinderTodo.js patch: fix comparison functions

Need at least 2 events with null values to see the null value problem.
'Location' is a field which may often be null. 
The problem arises because a comparison with null always returns false, so sort
doesn't work.
  null < "A" --> false
  "A" < null --> false

Another problem is the previous compare function never returned 0, so
sort was not stable when items are equal.  Stable sort is important
for sorting by multiple columns.  For example, to sort by date and 
by priority, just click the priority column and then the date column.
This works if the sort is stable, so the items within the same date
stay in the same priority order.

A minor nit is clicking on a date sorted the null/00 date earliest,
but it may be an incomplete task which would be better sorted as if
the date was 'now'.

Changes:

Added function compareString which converts nulls into "" before
comparing them, and returns 0 for equal strings.

Added function compareNumber which converts nulls into 0 before
comparing them, and returns 0 for equal numbers.

Added function compareDate which converts nulls and the
0000-00-00 00:00:00 time into the 'now' time when the sort started,
so that incomplete undated tasks sort to now.
The treeView.sortStartedTime is updated once just before each sort
so that holds the current 'now' but does not change during the sort.

Renamed sortEvents(a,b) to compareEvents(a,b).
Renamed sortTasks(a,b) to compareTasks(a,b).

Rewrote compareEvents and compareTasks to call the compareString,
compareNumber, and compareDate functions.

Testing:

Sorting each column works on both 1.7rc3 Suite and 1.8a2 Sunbird.
Stability will come as soon as bug 224128 is fixed.
(Reporter)

Updated

14 years ago
Depends on: 245844
(Reporter)

Updated

14 years ago
Blocks: 189710
(Assignee)

Comment 2

14 years ago
Checked in. Thanks
Status: NEW → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED
The bugspam monkeys have been set free and are feeding on Calendar :: Sunbird Only. Be afraid for your sanity!
QA Contact: gurganbl → sunbird
You need to log in before you can comment on or make changes to this bug.