table column with subobjects

This commit is contained in:
Sebastian Frank 2017-08-25 13:28:57 +02:00
parent 038582b454
commit 5b250b02fe
No known key found for this signature in database
GPG Key ID: DC2BC5C506EBF6F3
2 changed files with 16 additions and 2 deletions

View File

@ -13,7 +13,7 @@
<tbody is="transition-group" name="list"> <tbody is="transition-group" name="list">
<tr v-for="(r, ri) in rows" :key="ri"> <tr v-for="(r, ri) in rows" :key="ri">
<td v-for="(c, ci) in columns" :key="ci + 'c'"> <td v-for="(c, ci) in columns" :key="ci + 'c'">
<span v-if="c.prop">{{ r[c.prop] }}</span> <span v-if="c.prop">{{ getProp(r, c.prop) }}</span>
<span v-else-if="c.render">{{ c.render(r) }}</span> <span v-else-if="c.render">{{ c.render(r) }}</span>
</td> </td>
</tr> </tr>
@ -51,6 +51,16 @@ export default {
orderBy: col, orderBy: col,
orderDesc: false orderDesc: false
}); });
},
getProp(row, prop) {
let props = prop.split('.');
let val = row;
props.forEach((p) => {
if (typeof val == 'object') {
val = val[p];
}
});
return val;
} }
} }
} }

View File

@ -26,10 +26,14 @@ export default {
prop: 'Username', prop: 'Username',
orderBy: 'username' orderBy: 'username'
}, },
{
heading: 'Reseller',
prop: 'Reseller.Username'
},
{ {
heading: 'Render', heading: 'Render',
render(row) { render(row) {
return row.ID; return 'ID:' + row.ID;
} }
} }
], ],