diff --git a/src/main/webapp/resources/js/base/dataset.js b/src/main/webapp/resources/js/base/dataset.js index 6369fc0f..76324a3b 100644 --- a/src/main/webapp/resources/js/base/dataset.js +++ b/src/main/webapp/resources/js/base/dataset.js @@ -450,6 +450,10 @@ class Dataset { this._byKeys = {}; this._current = null; + let data = this._getDataItems(obj); + this._items = data.items; + this._byKeys = data.byKeys; + /* obj = obj || {}; let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || []; if (!Array.isArray(array)) @@ -460,12 +464,62 @@ class Dataset { let key = "key-" + this.getKey(item.data); this._byKeys[key] = item; }); + */ + this.onDatasetChange(obj); + this.setState(!Array.isArray(obj) ? obj.state : state); + this.onDirtiesChange(this.dirty); + + return this; + } + + _getDataItems(obj) { + obj = obj || {}; + let array = Array.isArray(obj) ? obj : this.conf.dataGetter(obj) || []; + if (!Array.isArray(array)) + throw new Error("The data must be an array"); + + let _items = array.map(e => new DataItem(e, this._formats)), + _byKeys = {}; + _items.forEach(item => { + let key = "key-" + this.getKey(item.data); + _byKeys[key] = item; + }); + + return { + items: _items, + byKeys: _byKeys + }; + } + + /**Adds user data to the Dataset. + * To get user data from an object, the dataGetter configured is called. + * After user data is set, the methods + *