add find-as-you-type to (static) text list

This commit is contained in:
rolux 2011-05-24 16:10:08 +02:00
parent 187adae7e2
commit 05af51f76b
2 changed files with 18 additions and 1 deletions

View file

@ -1282,6 +1282,7 @@ Ox.List = function(options, self) {
} else if (key == 'selected') {
Ox.print('setOption selected', value)
setSelected(value);
triggerSelectEvent();
} else if (key == 'sort') {
Ox.print('---sort---')
updateSort();

View file

@ -67,7 +67,8 @@ Ox.TextList = function(options, self) {
key_right: function() {
var $element = that.$body.$element;
$element[0].scrollLeft = $element[0].scrollLeft + $element.width();
}
},
keys: find
});
self.options.columns.forEach(function(v) { // fixme: can this go into a generic ox.js function?
@ -480,6 +481,21 @@ Ox.TextList = function(options, self) {
});
}
function find(data) {
// fixme: works only if items are an array
var query = data.keys,
sort = self.options.sort[0];
Ox.forEach(self.options.items, function(item, i) {
var value = (
sort.map ? sort.map(item[sort.key]) : item[sort.key]
).toLowerCase();
if (Ox.startsWith(value, query)) {
that.$body.options({selected: [item[self.unique]]});
return false;
}
});
}
function getCell(id, key) {
Ox.print('getCell', id, key)
var $item = getItem(id);