From 5d09a236fa9da71208db8a6f3eaeaeca640f1c36 Mon Sep 17 00:00:00 2001 From: Julien ROUSSEAU Date: Thu, 14 Jan 2016 16:17:12 +0100 Subject: [PATCH] Update header dynamically --- paper-datatable-column.html | 12 +++++++++--- paper-datatable.html | 10 ++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/paper-datatable-column.html b/paper-datatable-column.html index 656c694..b8d1740 100644 --- a/paper-datatable-column.html +++ b/paper-datatable-column.html @@ -39,7 +39,11 @@ * @type String * @required */ - header: String, + header: { + type: String, + notify: true, + observer: '_headerChanged' + }, /** * The property to be used from `data` for this column * @@ -434,8 +438,10 @@ }else if(type.toLowerCase() == 'number'){ return 'number'; } - } - + }, + _headerChanged: function(header) { + this.fire('header-changed'); + }, }); })(); diff --git a/paper-datatable.html b/paper-datatable.html index d1c8907..1dd5c85 100644 --- a/paper-datatable.html +++ b/paper-datatable.html @@ -510,13 +510,15 @@ _queryAndSetColumns: function(){ var columns = this.queryAllEffectiveChildren('paper-datatable-column'); - columns.forEach((column) => { + columns.forEach((column, index) => { if(!column.beenAttached.state.ready){ column.parentNodeRef = this; this.async(function(){ column._registerEvilFunctions(); column.beenAttached.ready(); }); + column.index = index; + this.listen(column, 'header-changed', '_updateHeaderColumn'); } }); this.set('_columns', columns.filter((column) => !column.inactive)); @@ -1098,7 +1100,11 @@ } } - } + }, + _updateHeaderColumn: function(event){ + var column = Polymer.dom(event).localTarget; + this.notifyPath(`_columns.${column.index}.header`, this._columns[column.index].header); + }, }); })();