Sort empty titles last when title isn't primary sort
When sorting by Title, empty titles get sorted to the top of the items
list for visibility, but when sorting by another column and using the
title as a secondary/tertiary sort, empty titles should get sorted last
so that new empty items go to the end of the list rather than the
middle.
This is a little weird, and the alternative would be to just always sort
empty titles last even when sorting by Title, but this preserves the
current behavior for Title sorting. (Before f0f6772b01
titles weren't
used for secondary sorting at all, so there's no precedent for
title-sorting behavior when sorting by another column.)
Addresses #275
This commit is contained in:
parent
d69dc3d5a7
commit
41e2f3008e
1 changed files with 23 additions and 5 deletions
|
@ -1287,10 +1287,20 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
var unformatted = false;
|
||||
}
|
||||
|
||||
// Hash table of fields for which rows with empty values should be displayed last
|
||||
var emptyFirst = {
|
||||
title: true
|
||||
};
|
||||
// Set whether rows with empty values should be displayed last,
|
||||
// which may be different for primary and secondary sorting.
|
||||
var emptyFirst = {};
|
||||
switch (columnField) {
|
||||
case 'title':
|
||||
emptyFirst.title = true;
|
||||
break;
|
||||
|
||||
// When sorting by title we want empty titles at the top, but if not
|
||||
// sorting by title, empty titles should sort to the bottom so that new
|
||||
// empty items don't get sorted to the middle of the items list.
|
||||
default:
|
||||
emptyFirst.title = false;
|
||||
}
|
||||
|
||||
// Cache primary values while sorting, since base-field-mapped getField()
|
||||
// calls are relatively expensive
|
||||
|
@ -1459,7 +1469,15 @@ Zotero.ItemTreeView.prototype.sort = function(itemID)
|
|||
}
|
||||
|
||||
if (columnField !== 'title') {
|
||||
cmp = collation.compareString(1, b.getField('title', true), a.getField('title', true));
|
||||
fieldA = a.getField('title', true);
|
||||
fieldB = b.getField('title', true);
|
||||
|
||||
if (!emptyFirst.title) {
|
||||
if (fieldA === '' && fieldB !== '') return -1;
|
||||
if (fieldA !== '' && fieldB === '') return 1;
|
||||
}
|
||||
|
||||
cmp = collation.compareString(1, fieldB, fieldA);
|
||||
if (cmp !== 0) {
|
||||
return cmp;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue