PDA

View Full Version : Auto resize a List compoment



mrtndimitrov
23 Sep 2011, 9:35 AM
Hi,

I have a List that first is filled with 5 items. Then a filter is applied and the items become 2. The problem is that the list remains as high as before - when 5 items were loaded.

How can I resize the list compoment?

Thanks,

Martin

Champi
23 Sep 2011, 11:22 AM
Remove items from store and refresh the list (list.refresh)

mrtndimitrov
23 Sep 2011, 12:46 PM
I just filter the items from the store. I don't want to remove them. Then I refresh but doesn't seem to work.

Champi
23 Sep 2011, 8:58 PM
Do you use the filter property of store? i'm using it, and it works fine by me.

Here is an example :


filters: [
{
filterFn: function(item) {
if( item.get('discount').raw)
return item.get('discount').raw >= 50;
else
return false;
}
}
],

If that code doesn't work, post your code!

mrtndimitrov
23 Sep 2011, 11:35 PM
Hi,

I am basically trying to do an autocomplete functionality. Here is the code:

My business model:


Ext.regModel('RefData', {
fields: [
{name: 'key', type: 'string'}
]
});


The store:



var store = new Ext.data.Store({
model: 'RefData',
sorters: 'key',
proxy: {
type: 'memory',
reader: {
type: 'json',
root: ''
}
},
data: [
{key: "Neon"},
{key: "Nuron"},
{key: "Nion"},
{key: "Noon"},
{key: "Neun"}
]
});


Then, the list is wrapped in floating panel that initially is hidden:



var list = new Ext.List({
xtype: 'list',
store: store,
itemTpl: '<div><strong>{key}</strong></div>'
});


var panel = new Ext.Panel({
floating: true,
items:
[list]
});



Then, on the keyup event of a text field, the panel is shown after the store is filtered:



new Ext.form.Text({
label: 'Username',
listeners: {
keyup: {
fn: function(b){
store.clearFilter(true);
store.filterBy(function(record, id){
if(record.get('key').toLowerCase().indexOf(b.getValue().toLowerCase()) == 0){
return true;
} else {
return false;
}
});
list.refresh();
panel.doLayout();
panel.show();
console.log(list.getHeight());
}
}
}
})


When I type 'n', all records are shown and the list height is 235, then I type 'i' and the list height stays the same.

Champi
25 Sep 2011, 7:52 PM
Taking a quick look, it should work. Have you tried a doComponentLayout instead a doLayout?

mrtndimitrov
25 Sep 2011, 8:54 PM
Thanks for the suggestion but it doesn't work for me. I tried all combinations of doCompomentLayout on the list or the panel.