From 05af51f76b72d6b96b2ccaf886772063c92d8723 Mon Sep 17 00:00:00 2001 From: rolux Date: Tue, 24 May 2011 16:10:08 +0200 Subject: [PATCH] add find-as-you-type to (static) text list --- source/Ox.UI/js/List/Ox.List.js | 1 + source/Ox.UI/js/List/Ox.TextList.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js index 2fd9e787..0ec8891c 100644 --- a/source/Ox.UI/js/List/Ox.List.js +++ b/source/Ox.UI/js/List/Ox.List.js @@ -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(); diff --git a/source/Ox.UI/js/List/Ox.TextList.js b/source/Ox.UI/js/List/Ox.TextList.js index 9250fa19..55c65313 100644 --- a/source/Ox.UI/js/List/Ox.TextList.js +++ b/source/Ox.UI/js/List/Ox.TextList.js @@ -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);