We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 7462ed9 + 9d6e6ae commit 06e9c1bCopy full SHA for 06e9c1b
src/DataTable.spec.ts
@@ -143,6 +143,27 @@ describe("DataTable directive tests", ()=> {
143
{name: 'Claire', age: 16}
144
]);
145
});
146
+
147
+ it("should sort data by child property value", ()=>{
148
+ let newData = [
149
+ {name: 'Claire', city: { zip: '51111'}},
150
+ {name: 'Anna', city: { zip: '31111'}},
151
+ {name: 'Claire', city: { zip: '41111'}},
152
+ {name: 'Claire', city: { zip: '11111'}},
153
+ {name: 'Anna', city: { zip: '21111'}}
154
+ ];
155
+ datatable.ngOnChanges({inputData: new SimpleChange(datatable.inputData, newData)});
156
+ datatable.setSort("city.zip", "asc");
157
+ datatable.ngDoCheck();
158
159
+ expect(datatable.data).toEqual([
160
161
+ {name: 'Anna', city: { zip: '21111'}},
162
163
164
165
+ ]);
166
+ });
167
168
169
describe("data change", ()=> {
src/DataTable.ts
@@ -118,7 +118,10 @@ export class DataTable implements OnChanges, DoCheck {
118
119
private caseInsensitiveIteratee(sortBy: string) {
120
return (row: any): any => {
121
- var value = row[sortBy];
+ var value = row;
122
+ for (let sortByProperty of sortBy.split('.')){
123
+ value = value[sortByProperty];
124
+ }
125
if (value && typeof value === 'string' || value instanceof String) {
126
return value.toLowerCase();
127
}
0 commit comments