Skip to content

Commit 198f6c1

Browse files
committed
Fix nested elements sorting
1 parent 1703951 commit 198f6c1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/DataTable.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,9 @@ describe("DataTable directive tests", ()=> {
291291
it("should sort data by child property value", ()=> {
292292
let newData = [
293293
{name: 'Claire', city: {zip: '51111'}},
294-
{name: 'Anna', city: {zip: '31111'}},
294+
{name: 'Anna'},
295295
{name: 'Claire', city: {zip: '41111'}},
296+
{name: 'Donald', city: 2},
296297
{name: 'Claire', city: {zip: '11111'}},
297298
{name: 'Anna', city: {zip: '21111'}}
298299
];
@@ -303,9 +304,10 @@ describe("DataTable directive tests", ()=> {
303304
expect(datatable.data).toEqual([
304305
{name: 'Claire', city: {zip: '11111'}},
305306
{name: 'Anna', city: {zip: '21111'}},
306-
{name: 'Anna', city: {zip: '31111'}},
307307
{name: 'Claire', city: {zip: '41111'}},
308308
{name: 'Claire', city: {zip: '51111'}},
309+
{name: 'Anna'},
310+
{name: 'Donald', city: 2},
309311
]);
310312
});
311313
});

src/DataTable.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ export class DataTable implements OnChanges, DoCheck {
153153
return (row: any): any => {
154154
var value = row;
155155
for (let sortByProperty of sortBy.split('.')) {
156-
value = value[sortByProperty];
156+
if(value) {
157+
value = value[sortByProperty];
158+
}
157159
}
158160
if (value && typeof value === 'string' || value instanceof String) {
159161
return value.toLowerCase();

0 commit comments

Comments
 (0)