PDA

View Full Version : Add data to Picker



Zielke
24 Sep 2010, 5:55 AM
Hi again,

I add some data into a Picker.
The first time I open the Picker, it looks fine. But now if I add more data, the Picker still looks like the first time. The new data are still in the Picker but it won´t show the new data.

I tried update(), doLayout(), ... but it wont work.



var VarData=[];
for (var i = 0, ln = Data.length; i < ln; i++) {
VarData.push({
text: Data[i].name,
value: Data[i].id,
key: i
});
};

Picker.removeAll();

Picker.add({
name: VarName,
data: VarData
});

Am I on the wrong way or is it a bug?

aconran
24 Sep 2010, 9:47 AM
You will have to update the underlying store of the individual slot within the Picker.

Zielke
27 Sep 2010, 12:22 AM
I tried to update everything but I don´t get it.
It´s infuriatingly :( Someone a little example? That would be nice. Thanks

kortovos
13 Oct 2010, 2:36 AM
Anyone has an example of this? It would be really handy

kortovos
21 Oct 2010, 10:38 PM
You will have to update the underlying store of the individual slot within the Picker.

Nothing in the API documentation indicates anything about a picker using a store.

Here is the method I use.

var picker = new Ext.Picker({
slots: [],
height: '300',
listeners:{
beforeshow:function(){
var one = {
name : 'One',
title: 'One',
data : []
};
for(var i =0; i< 10; i++){
one.data[i] = {text: i, value : i};
}
picker.add(one);

var two = {
name : 'Two',
title: 'Two',
data : []
};
for(var i =0; i< 10; i++){
two.data[i] = {text: i, value : i};
}
picker.add(two);

var three = {
name : 'Three',
title: 'Three',
data : []
};
for(var i =0; i< 10; i++){
three.data[i] = {text: i, value : i};
}
picker.add(three);


var four = {
name : 'Four',
title: 'Four',
data : []
};
for(var i =0; i< 10; i++){
four.data[i] = {text: i, value : i};
}
picker.add(four);

var five = {
name : 'Five',
title: 'Five',
data : []
};
for(var i =0; i< 10; i++){
five.data[i] = {text: i, value : i};
}
picker.add(five);

var six = {
name : 'Six',
title: 'Six',
data : []
};
for(var i =0; i< 10; i++){
six.data[i] = {text: i, value : i};
}
picker.add(six);

picker.doLayout();
}
}
});

But I still have no way of setting the selected values of a picker when it appears. Anyone got any idea, or a working example of the .setValue() function?

kortovos
21 Oct 2010, 11:28 PM
Got it working, even so that the virtual keyboard of the Ipad or Iphone doesn't appear.
I am using a picker to enable a user to input the mileage of his car. (up to 999.999 km)


xtype : 'numberfield',
name : 'car_mileage',
label : 'Mileage',
id : 'page2Mileage',
listeners : {
focus : function(field) {
field.fieldEl.dom.blur();
picker.show(field);
},
afterrender : function(c) {
c.fieldEl.dom.readOnly = true;
}
}It adds 6 slots with values from 0 to 9 the first time it is shown. It also sets the selected values of the slots to those of the numberfield.

var picker = new Ext.Picker( {
slots : [],
height : 300,
width : 500,
stretchX : false,
centered : true,
useTitles: false,
listeners : {
beforeshow : function() {
if (this.items.length < 6) {
var one = {
name : '1',
title : '1',
data : []
};
for ( var i = 0; i < 10; i++) {
one.data[i] = {
text : i,
value : i
};
}
picker.add(one);

var two = {
name : '2',
title : '2',
data : []
};
for ( var i = 0; i < 10; i++) {
two.data[i] = {
text : i,
value : i
};
}
picker.add(two);

var three = {
name : '3',
title : '3',
data : []
};
for ( var i = 0; i < 10; i++) {
three.data[i] = {
text : i,
value : i
};
}
picker.add(three);

var four = {
name : '4',
title : '4',
data : []
};
for ( var i = 0; i < 10; i++) {
four.data[i] = {
text : i,
value : i
};
}
picker.add(four);

var five = {
name : '5',
title : '5',
data : []
};
for ( var i = 0; i < 10; i++) {
five.data[i] = {
text : i,
value : i
};
}
picker.add(five);

var six = {
name : '6',
title : '6',
data : []
};
for ( var i = 0; i < 10; i++) {
six.data[i] = {
text : i,
value : i
};
}
picker.add(six);
picker.doLayout();
}
var mileage = Ext.getCmp('page2Mileage').getValue();
mileage = Ext.util.Format.leftPad(mileage, 6, '0');
this.setValue({1:mileage.substring(0,1),2:mileage.substring(1,2),3:mileage.substring(2,3),4:mileage.substring(3,4),5:mileage.substring(4,5),6:mileage.substring(5,6)});
},
beforehide : function() {
var mileage = '';
Ext.iterate(this.getValue(), function(key, value) {
mileage += value;
})
Ext.getCmp('page2Mileage').setValue(mileage);
}
}
});

Riaz
30 Mar 2011, 7:33 PM
Is it possible to add json data into the slots?