1
0
Fork 0
forked from 0x2620/oxjs

lists: implement select-as-you-type

This commit is contained in:
rolux 2012-06-29 14:19:34 +02:00
commit 64a182ae1d
4 changed files with 85 additions and 61 deletions

View file

@ -32,6 +32,7 @@ Ox.TableList <f> TableList Widget
pageLength <n|100> Number of items per page
query <o> Query
scrollbarVisible <b|false> If true, the scrollbar is always visible
selectAsYouType <s|''> If set to a key, enables select-as-you-type
selected <[s]|[]> Array of selected ids
sort <[o]|[s]|[]> ['+foo', ...] or [{key: 'foo', operator: '+'}, ...]
sortable <b|false> If true, elements can be re-ordered
@ -104,8 +105,7 @@ Ox.TableList = function(options, self) {
var $element = that.$body.$element,
scrollLeft = $element[0].scrollLeft + $element.width();
$element.animate({scrollLeft: scrollLeft}, 250);
},
keys: find
}
});
self.options.columns.forEach(function(column) { // fixme: can this go into a generic ox.js function?
@ -246,6 +246,7 @@ Ox.TableList = function(options, self) {
pageLength: self.options.pageLength,
paste: self.options.paste,
query: self.options.query,
selectAsYouType: self.options.selectAsYouType,
selected: self.options.selected,
sort: self.options.sort,
sortable: self.options.sortable,
@ -596,23 +597,6 @@ Ox.TableList = function(options, self) {
});
}
function find(data) {
// fixme: works only if items are an array
var query = data.keys,
sort = self.options.sort[0];
Ox.Log('List', 'QUERY', query)
Ox.forEach(self.options.items, function(item, i) {
var value = (
sort.map ? sort.map(item[sort.key]) : item[sort.key]
).toString().toLowerCase();
if (Ox.startsWith(value, query)) {
that.$body.options({selected: [item[self.options.unique]]});
Ox.Log('List', 'QUERY', query, 'VALUE', value)
Ox.Break();
}
});
}
function formatValue(key, value, data) {
// fixme: this may be obscure...
// since the format of a value may depend on another value,