Skip to content

Commit

Permalink
Merge branch 'sortEmpty'
Browse files Browse the repository at this point in the history
  • Loading branch information
Saulis committed Apr 21, 2017
2 parents 24f123d + 7316726 commit 9931b6f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
8 changes: 1 addition & 7 deletions array-datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ function ArrayDataSource(arr) {
}

function _compare(a, b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
return (a===undefined)-(b===undefined) || (a==='')-(b==='') || (a===null)-(b===null) || +(a>b)||-(a<b);
}

function _sort(items, sortOrder) {
Expand Down
44 changes: 44 additions & 0 deletions test/sorting.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,50 @@
expect(columnSort.direction).to.eql('desc');
});
});

describe('sorting empty values', function() {
beforeEach(function() {
});

it('should sort null values', function(done) {
grid.items = [{value: 'foo'}, {value: null}, {value: 'bar'}];

grid.push('sortOrder', {path: 'value', direction: 'asc'});

grid.async(function() {
expect(grid.$.list.items[0]).to.eql({value: 'bar'});
expect(grid.$.list.items[1]).to.eql({value: 'foo'});
expect(grid.$.list.items[2]).to.eql({value: null});
done();
}, 100);
});

it('should sort undefined values', function(done) {
grid.items = [{value: 'foo'}, {value: undefined}, {value: 'bar'}];

grid.push('sortOrder', {path: 'value', direction: 'asc'});

grid.async(function() {
expect(grid.$.list.items[0]).to.eql({value: 'bar'});
expect(grid.$.list.items[1]).to.eql({value: 'foo'});
expect(grid.$.list.items[2]).to.eql({value: undefined});
done();
}, 100);
});

it('should sort empty string values', function(done) {
grid.items = [{value: 'foo'}, {value: ''}, {value: 'bar'}];

grid.push('sortOrder', {path: 'value', direction: 'asc'});

grid.async(function() {
expect(grid.$.list.items[0]).to.eql({value: 'bar'});
expect(grid.$.list.items[1]).to.eql({value: 'foo'});
expect(grid.$.list.items[2]).to.eql({value: ''});
done();
}, 100);
});
})
});
</script>

Expand Down

0 comments on commit 9931b6f

Please sign in to comment.