Skip to content
Closed
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
1 change: 1 addition & 0 deletions demo/paper-datatable/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<paper-datatable-column header="Complex Array" property="complexArr" type="Array" array-display-prop="title"></paper-datatable-column>
<paper-datatable-column id="dateTest" header="Created" property="created" type="Date" sortable format-value="{{formatDate}}"></paper-datatable-column>
<paper-datatable-column id="dateTest" header="Created" property="created" type="Date" sortable></paper-datatable-column>
<paper-datatable-column header="Nested" property="complexObj.a" type="String" editable dialog edit-icon sortable></paper-datatable-column>
</paper-datatable>
</paper-card>

Expand Down
26 changes: 21 additions & 5 deletions paper-datatable-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
*/
header: String,
/**
* The property to be used from `data` for this column
* The property to be used from `data` for this column. Use dot to access
* nested children.
*
* @attribute property
* @type String
Expand Down Expand Up @@ -286,10 +287,12 @@
},

_createCellInstance: function(model, notificationKey){
if(typeof model[this.property] == 'undefined' && typeof this.default !== 'undefined'){
var val = this._getValueByProperty(model);

if(typeof val == '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: val, _dataKey: notificationKey});
}
return instance;
},
Expand Down Expand Up @@ -363,6 +366,15 @@
}
},

_getValueByProperty: function(dataObj){
var propertyPath = this.property.split('.');
var val = dataObj;
for (var i = 0; i < propertyPath.length && typeof val != 'undefined'; i++) {
val = val[propertyPath[i]];
}
return val;
},

_forwardParentProp: function(prop, value){
console.warn('_forwardParentProp',arguments);
},
Expand All @@ -373,8 +385,10 @@
_forwardInstanceProp: function(templateInstance, prop, value){
var path = prop.split('.');
var item = path.shift();
var propertyPath = this.property.split('.');

if(item == 'value'){
var parentPath = ['data', templateInstance.get('_dataKey'), this.property];
var parentPath = ['data', templateInstance.get('_dataKey')].concat(propertyPath);
value = this._cast(value);
//console.log('_forwardInstanceProp',arguments);
//console.log('set', parentPath, 'to', value);
Expand All @@ -387,8 +401,10 @@
_forwardInstancePath: function(templateInstance, prop, value){
var path = prop.split('.');
var item = path.shift();
var propertyPath = this.property.split('.');

if(item == 'value'){
var parentPath = ['data', templateInstance.get('_dataKey'), this.property].concat(path);
var parentPath = ['data', templateInstance.get('_dataKey')].concat(propertyPath[0]).concat(path);
if(path.length == 0){
value = this._cast(value);
}
Expand Down
52 changes: 46 additions & 6 deletions paper-datatable.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,46 @@
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-tooltip/paper-tooltip.html">

<script src="weakCache.js"></script>
<script>
/*
IMPORTANT: Right now this Cache is **not** weak in the sense that it discards items based memory pressure, however
it is written in a way that will allow this later to be added without rewriting the rest of the code and right now
'emulates' the behaviour by having a fixed maximum of items.
*/
var WeakCache = function(limit){
var values = [];
var keys = [];
return {
set: function (key, obj) {
var index = keys.indexOf(key);
if(index > -1){
values[index] = obj;
values.splice(values.length, 0, values.splice(index, 1)[0]);
keys.splice(keys.length, 0, keys.splice(index, 1)[0]);
}else{
keys.push(key);
values.push(obj);
if(keys.length > limit){
keys.shift();
values.shift();
}
}
},
has: function(key){
return keys.indexOf(key) > -1;
},
get: function(key){
var index = keys.indexOf(key);
return values[index];
},
delete: function(key){
var index = keys.indexOf(key);
values.splice(index, 1);
keys.splice(index, 1);
}
}
}
</script>

<dom-module id="paper-datatable">
<template>
Expand Down Expand Up @@ -600,7 +639,7 @@
if(isEmpty || isWrongRow || isWrongColumn){
cell.removeAttribute('data-empty');
var prop = cell.dataColumn.property;
var data = rowData[prop];
var data = cell.dataColumn._getValueByProperty(rowData);

cell.setAttribute('data-row-key', row.dataset.key);
cell.dataBoundColumn = cell.dataColumn;
Expand Down Expand Up @@ -667,8 +706,9 @@
for(var i=0; i<cells.length;i++){
var cell = cells[i];
var prop = cell.dataColumn.property;
var propertyPath = prop.split('.');

if(prop == path[0]){
if(prop == path.join(".")){
if(cell.instance){
var localPath = path.slice();
localPath.shift();
Expand All @@ -677,7 +717,7 @@
cell.instance.notifyPath(instanceValuePath, change.value);
}
if(!cell.instance || cell.instanceType == 'dialog'){
cell.querySelector('span').innerHTML = this._columns[i]._formatValue(this.get([object, rowKey, prop]));
cell.querySelector('span').innerHTML = this._columns[i]._formatValue(this.get([object, rowKey].concat(propertyPath)));
}
}
if(cell.instance){
Expand Down Expand Up @@ -893,8 +933,8 @@
a = b;
b = c;
}
var valA = this._getByKey(a)[column.property];
var valB = this._getByKey(b)[column.property];
var valA = column._getValueByProperty(this._getByKey(a));
var valB = column._getValueByProperty(this._getByKey(b));
return column._sort(valA, valB);
}.bind(this));
this.set("_rowKeys", JSON.parse(JSON.stringify(this._rowKeys)));
Expand Down