Skip to content

Commit

Permalink
Don’t normalize values into strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Mar 28, 2017
1 parent ea7cbd2 commit 1237ff8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions test/sorting.html
Expand Up @@ -370,6 +370,21 @@
expect(getBodyCellContent(grid, 1, 0).innerText).to.equal('foo');
expect(getBodyCellContent(grid, 2, 0).innerText).to.equal('NaN');
});

it('should sort numbers correctly', function() {
grid.items = [{
first: 1
}, {
first: 2
}, {
first: 11
}];

expect(getBodyCellContent(grid, 0, 0).innerText).to.equal('1');
expect(getBodyCellContent(grid, 1, 0).innerText).to.equal('2');
expect(getBodyCellContent(grid, 2, 0).innerText).to.equal('11');
});

});

describe('data provider', function() {
Expand Down
10 changes: 8 additions & 2 deletions vaadin-grid-array-data-provider-behavior.html
Expand Up @@ -94,7 +94,13 @@
},

_normalizeEmptyValue: function(value) {
return [undefined, null].indexOf(value) >= 0 ? '' : value.toString();
if ([undefined, null].indexOf(value) >= 0) {
return '';
} else if (isNaN(value)) {
return value.toString();
} else {
return value;
}
},

_compare: function(a, b) {
Expand All @@ -114,7 +120,7 @@
return items.filter(function(item, index) {
return this._filters.filter(function(filter) {
var value = this._normalizeEmptyValue(Polymer.Base.get(filter.path, item));
return value.toLowerCase().indexOf(filter.value.toString().toLowerCase()) === -1;
return value.toString().toLowerCase().indexOf(filter.value.toString().toLowerCase()) === -1;
}.bind(this)).length === 0;
}, this);
}
Expand Down

0 comments on commit 1237ff8

Please sign in to comment.