TableList: add 'unique' option (until now, the unique id had be specified via columns, even if one had no intention to ever display it as a column)
This commit is contained in:
parent
27ea70784c
commit
773311d8d7
1 changed files with 21 additions and 14 deletions
|
@ -6,7 +6,6 @@ Ox.TableList <f> TableList Widget
|
|||
options <o> Options object
|
||||
columns <[o]|[]> Columns
|
||||
# Fixme: There's probably more...
|
||||
addable <b> ...
|
||||
editable <b> ...
|
||||
format <f> ...
|
||||
id <s> ...
|
||||
|
@ -16,7 +15,7 @@ Ox.TableList <f> TableList Widget
|
|||
title <s> ...
|
||||
titleImage <s> ...
|
||||
unformat <f> Applied before editing
|
||||
unique <b> If true, this column acts as unique id
|
||||
unique <b> If true, this column acts as unique id (deprecated)
|
||||
visible <b> ...
|
||||
width <n> ...
|
||||
columnsMovable <b|false> If true, columns can be re-ordered
|
||||
|
@ -37,6 +36,9 @@ Ox.TableList <f> TableList Widget
|
|||
sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...]
|
||||
sortable <b|false> If true, elements can be re-ordered
|
||||
sums <[s]|[]> Sums to be included in totals
|
||||
unique <s|''> Key of the unique id
|
||||
This has precedence over a unique id specified via columns (which is
|
||||
deprecated).
|
||||
columnresize <!> columnresize
|
||||
columnchange <!> columnchange
|
||||
self <o> 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_
|
||||
|
|
Loading…
Reference in a new issue