diff --git a/source/Ox.UI/js/List/TableList.js b/source/Ox.UI/js/List/TableList.js index 1a30a9f9..ef298c20 100644 --- a/source/Ox.UI/js/List/TableList.js +++ b/source/Ox.UI/js/List/TableList.js @@ -6,7 +6,6 @@ Ox.TableList TableList Widget options Options object columns <[o]|[]> Columns # Fixme: There's probably more... - addable ... editable ... format ... id ... @@ -16,7 +15,7 @@ Ox.TableList TableList Widget title ... titleImage ... unformat Applied before editing - unique If true, this column acts as unique id + unique If true, this column acts as unique id (deprecated) visible ... width ... columnsMovable If true, columns can be re-ordered @@ -37,6 +36,9 @@ Ox.TableList TableList Widget sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...] sortable If true, elements can be re-ordered sums <[s]|[]> Sums to be included in totals + unique Key of the unique id + This has precedence over a unique id specified via columns (which is + deprecated). columnresize columnresize columnchange columnchange self shared private variable @@ -69,7 +71,8 @@ Ox.TableList = function(options, self) { selected: [], sort: [], sortable: false, - sums: [] + sums: [], + unique: '' }) .options(options || {}) .update({ @@ -129,15 +132,15 @@ Ox.TableList = function(options, self) { if (Ox.isUndefined(column.visible)) { column.visible = false; } - if (column.unique) { - self.unique = column.id; + if (column.unique && !self.options.unique) { + self.options.unique = column.id; } }); if (Ox.isEmpty(self.options.sort)) { self.options.sort = [{ - key: self.unique, - operator: Ox.getObjectById(self.options.columns, self.unique).operator + key: self.options.unique, + operator: Ox.getObjectById(self.options.columns, self.options.unique).operator }]; } @@ -225,9 +228,13 @@ Ox.TableList = function(options, self) { items: self.options.items, itemWidth: getItemWidth(), format: self.format, // fixme: not needed, happens in TableList - keys: self.visibleColumns.map(function(column) { - return column.id; - }).concat(self.options.keys), + keys: Ox.unique( + self.visibleColumns.map(function(column) { + return column.id; + }) + .concat(self.options.unique) + .concat(self.options.keys) + ), max: self.options.max, min: self.options.min, orientation: 'vertical', @@ -239,7 +246,7 @@ Ox.TableList = function(options, self) { sortable: self.options.sortable, sums: self.options.sums, type: 'text', - unique: self.unique + unique: self.options.unique }, Ox.extend(Ox.clone(self), {updateCallbacks: []})) // pass event handler .addClass('OxBody') .css({ @@ -458,7 +465,7 @@ Ox.TableList = function(options, self) { if (v.tooltip) { $cell = Ox.Element({ tooltip: function() { - return self.options.selected.indexOf(data[self.unique]) > -1 + return self.options.selected.indexOf(data[self.options.unique]) > -1 ? (Ox.isString(v.tooltip) ? v.tooltip : v.tooltip(data)) : ''; } }); @@ -594,7 +601,7 @@ Ox.TableList = function(options, self) { sort.map ? sort.map(item[sort.key]) : item[sort.key] ).toString().toLowerCase(); if (Ox.startsWith(value, query)) { - that.$body.options({selected: [item[self.unique]]}); + that.$body.options({selected: [item[self.options.unique]]}); Ox.Log('List', 'QUERY', query, 'VALUE', value) Ox.Break(); } @@ -1027,7 +1034,7 @@ Ox.TableList = function(options, self) { return that.$body.value(id, key); } else { that.$body.value(id, key, value); - if (key == self.unique) { + if (key == self.options.unique) { // unique id has changed self.options.selected = self.options.selected.map(function(id_) { return id_ == id ? value : id_