Finished dynamic table

pull/3/head
Max Ehrlicher-Schmidt 4 years ago
parent 6172db4c0c
commit 589d5d830c

@ -69,9 +69,9 @@ export class BikesComponent {
this.dataColumns = []; this.dataColumns = [];
this.addColumnsFromObject('', this.data[0]); this.addColumnsFromObject('', this.data[0]);
for (let row of this.data) { for (let index in this.data) {
row = this.flatten(row); this.data[index] = this.flatten(this.data[index]);
} }
//sort, so the displayedColumns array is in the same order as the columnInfo //sort, so the displayedColumns array is in the same order as the columnInfo
@ -119,23 +119,42 @@ export class BikesComponent {
} }
} }
flatten(object: Object, prefix: string = '') { flatten(object: Object, prefix: string = ''): any {
let newObject = new Object(); let newObject = {};
for (const prop in object) { for (const prop in object) {
let propName = prefix + prop; let propName = prefix + prop;
if (typeof object[prop] === 'object' && object[prop] !== null) { if (typeof object[prop] === 'object' && object[prop] !== null) {
const flattenedObject = this.flatten(object[prop], propName + '.'); const flattenedObject = this.flatten(object[prop], propName + '.');
console.log(flattenedObject);
for (const flattenedProperty in flattenedObject) { for (const flattenedProperty in flattenedObject) {
console.log(flattenedProperty); newObject[flattenedProperty] =
Object.defineProperty(newObject, flattenedProperty, { flattenedObject[flattenedProperty];
value: object[flattenedProperty],
});
} }
} else if(!prop.includes('_', 0)) {
newObject[propName] = object[prop];
}
}
return newObject;
}
deepen(object: Object): any {
let newObject = {};
for (const prop in object) {
if (prop.includes('.')) {
const splittedProp = prop.split('.');
const outerProp = splittedProp[0];
const innerProp = splittedProp.slice(1).join('.');
if (!newObject[outerProp]) {
newObject[outerProp] = {};
}
newObject[outerProp][innerProp] = object[prop];
} else { } else {
Object.defineProperty(newObject, propName, { value: object[prop] }); newObject[prop] = object[prop];
} }
} }
for (const prop in newObject) {
if (typeof newObject[prop] === 'object' && newObject[prop] !== null)
newObject[prop] = this.deepen(newObject[prop]);
}
return newObject; return newObject;
} }
@ -188,11 +207,12 @@ export class BikesComponent {
} }
save(row: CargoBikeResult) { save(row: CargoBikeResult) {
const bike: CargoBikeUpdateInput = filter( const bla: CargoBikeUpdateInput = filter(
CargoBikeFieldsMutableFragmentDoc, CargoBikeFieldsMutableFragmentDoc,
row this.deepen(row)
); );
this.bikesService.updateBike({ bike }); console.log(bla);
this.bikesService.updateBike({ bike: bla });
} }
cancel(row: CargoBikeResult) { cancel(row: CargoBikeResult) {

Loading…
Cancel
Save