Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested property names #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions demo/paper-datatable/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
</paper-datatable>
</paper-card>

<paper-card>
<paper-datatable data="{{data}}" selectable>
<paper-datatable-column header="Dessert (100g serving)" property="title" type="String" tooltip="Some title" sortable> </paper-datatable-column>
<paper-datatable-column header="Object a" property="complexObj.a" tooltip="The total amount of..." sortable>
</paper-datatable-column>
<paper-datatable-column header="Object b" property="complexObj.b" tooltip="The total amount of..." sortable>
</paper-datatable-column>
</paper-datatable>
</paper-card>

<paper-card>
<paper-datatable data="{{data}}" selectable multi-selection>
<paper-datatable-column header="Dessert (100g serving)" property="title" type="String" tooltip="Some title" sortable> </paper-datatable-column>
Expand All @@ -81,6 +91,18 @@
</template>
</template>
</paper-datatable-column>
<paper-datatable-column header="Object Single element" property="complexObj.b" tooltip="The total amount of..." sortable>
<template>
<paper-input value="{{value}}"></paper-input>
</template>
</paper-datatable-column>
<paper-datatable-column header="Very Complexe Object" property="veryComplexObj.a.x" tooltip="The total amount of..." sortable>
<template>
<template is="dom-repeat" items="{{value}}" as="valueItem">
<paper-input value="{{valueItem}}"></paper-input>
</template>
</template>
</paper-datatable-column>
</paper-datatable>
</paper-card>

Expand Down Expand Up @@ -109,9 +131,9 @@
return this.get(path);
};
app.data = [
{title: 'Ice cream', yummy: true, calories: 2000, complexObj: {a: 'b', b: 'd'}, arr: [2,3,4], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447315235838)},
{title: 'Dessert', yummy: true, calories: 3000, complexObj: {a: 'bb', b: 'dd'}, arr: [5,6], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447155235838)},
{title: 'Cake', yummy: false, calories: 4000, complexObj: {a: 'cc', b: 'gg'}, arr: [7,8], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447355135838)}
{title: 'Ice cream', yummy: true, calories: 2000, veryComplexObj: {a: {x: ['b', 'c']}}, complexObj: {a: 'b', b: 'd'}, arr: [2,3,4], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447315235838)},
{title: 'Dessert', yummy: true, calories: 3000, veryComplexObj: {a: {x: ['b', 'c']}}, complexObj: {a: 'bb', b: 'dd'}, arr: [5,6], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447155235838)},
{title: 'Cake', yummy: false, calories: 4000, veryComplexObj: {a: {x: ['b', 'c']}}, complexObj: {a: 'cc', b: 'gg'}, arr: [7,8], complexArr: [{title:'b'}, {title:'c'}], created: new Date(1447355135838)}
];
app.log = function(ev){
console.info('event', ev.type, 'on', ev.target, 'with detail', ev.detail);
Expand Down
8 changes: 6 additions & 2 deletions paper-datatable-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,14 @@
},

_createCellInstance: function(model, notificationKey){
if(typeof model[this.property] == 'undefined' && typeof this.default !== 'undefined'){
var modelDefined = model[this.property];
if (!modelDefined && this.property) {
this.property.split('.').forEach(key => modelDefined = modelDefined ? modelDefined[key] : model[key]);
}
if(modelDefined == 'undefined' && typeof this.default !== 'undefined'){
var instance = this.stamp({item: model, column:this, value: this.default, _dataKey: notificationKey});
}else{
var instance = this.stamp({item: model, column:this, value: model[this.property], _dataKey: notificationKey});
var instance = this.stamp({item: model, column:this, value: modelDefined, _dataKey: notificationKey});
}
return instance;
},
Expand Down
3 changes: 3 additions & 0 deletions paper-datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@
cell.removeAttribute('data-empty');
var prop = cell.dataColumn.property;
var data = rowData[prop];
if (!data && prop) {
prop.split('.').forEach(key => data = data ? data[key] : rowData[key]);
}

cell.setAttribute('data-row-key', row.dataset.key);
cell.dataBoundColumn = cell.dataColumn;
Expand Down