How to configure the Ext.List launched from a selectfield in Sencha Touch? - sencha-touch

In Sencha Touch 2, I have a formpanel with a selectfield to pick from a large store of models. I can choose between an Ext.Picker or an Ext.List as the picker component by setting the usePicker property on the selectfield. But how do I configure the Ext.List?
I tried setting defaultPhonePickerConfig and defaultTabletPickerConfig, but that doesn't seem to work. Specifically, I want to set { grouped: true, indexBar: true } to help my users navigate the long list of options. I used the JavaScript debugger to trace the showPicker() method and verified that the instantiated Ext.List has those two properties set in its config property. But the list overlay still doesn't show the group headings or the index bar. Any idea what I could be doing wrong?

The solution is to defer configuration until after the panel component is painted:
usePicker: false,
defaultTabletPickerConfig: {
listeners: {
painted: function(panel) {
var list = panel.down('list');
list.setGrouped(true);
list.setIndexBar(true);
}
}
}
This is dumb.

Related

Sencha Touch ListView IndexBar + selectfield

I am new to sencha and would like to have the indexBar option to a listview which is launched by the selectfield. Tried with
defaultTabletPickerConfig:
{
listeners:
{
painted: function(panel)
{
var list = panel.down('list');
list.setIndexBar(true);
}
}
}
But this code doesn't work, please help.
If you new to sencha please do not use defaultTabletPickerConfig setting.
Please describe more what you want to get, share more code you have written.

Configuring a controller using Sencha Architect 2

I'm trying to achieve something fairly simple: use a controller to attach an event to a specific control, but am struggling to represent this using Sencha Architect.
I have a button named "Login-Button-Login".
In my controller, if I have the code:
config: {
control: {
"button": {
tap: 'onButtonTap'
}
}
},
onButtonTap: function(button, e, eOpts) {
Ext.Msg.alert("onButtonTap fired");
},
The the button works as expected. This is fine, but obviously it will apply to all buttons. I add a reference to "Login-Button-Login" (not my choice of name!):
config: {
refs: {
loginButtonTap: 'Login-Button-Login'
},
control: {
"button": {
tap: 'onButtonTap'
},
"Login-Button-Login": {
tap: 'onButtonTap2'
}
}
},
But how can I now use the reference "loginButtonTap" as an item in the control object? Whatever I try using the Sencha Architect controls I just end up with "Login-Button-Login" being referenced directly.
Relatedly, how can I link this controller to the "Login" view which contains the button? Surely I don't need to use full selectors for each reference? Clearly even if I could make this work, it currently would not function as Login-Button-Login needs to reference the "Login" view.
Just use an id (or itemId) of the control as the value of the controlQuery in event handler config:
config: {
control: {
"#btnWhatever": {
tap: 'onWhateverTap'
},
}
I prefer to use this method of attaching events to elements, since I am too lazy to do double work - specify the reference to the button, and then specify that reference in event handlers controlQuery. onWhateverTap gets the reference to the button as an argument and most of the time you do not need that reference anywhere else.

Extjs4 listener for window

In my application i have many windows and panels and im using custom scrollbars. So for each window or panel i need to specify afterlayout listener to get the custom scroll bar
listeners:{
afterlayout: function(c){
fleXenv.fleXcrollMain(c.body.id);
}
}
So what im looking for is i need to add this listener globally for windows and panels so that by adding this code one time should effect on all windows or panels.
Is there any way to do this
It seems that your custom scrollbar is used in all Windows and Panels of your application. Hence there is nothing wrong with extending the core ExtJs classes IMHO.
Implement it as a 'feature' that is enabled by default but - for the rare cases where you don't want the scrollbar - can be disabled.
Ext.define('patch.Ext.panel.Panel-scrollbar', {
override: 'Ext.panel.Panel',
enableCustomScrollbar: true,
afterLayout: function() {
this.fixScrollbar();
this.callParent(arguments);
},
fixScrollbar: function() {
if(this.enableCustomScrollbar) {
// your code
}
}
});
Load with Ext.require('patch.Ext.panel.Panel-scrollbar') or add it as dependency (requires) to your application definition.
Ext.window.Window extends from Ext.panel.Panel, hence it will inherit the behavior.
You can make your own panel and window extending ExtJS default components. You can define desired listener, set up xtypes and then use these modified components in your application.
Another solution would be to override existing Ext.panel.Panel and Ext.window.Window with Ext.override
IMHO, I think the best way to do this is to define your personal Window/Panel class. Yes, one way is to use Ext.override function but I don't think it's a good idea.
I suggest you to do this:
Ext.define ('MyCustomWindow', {
extend: 'Ext.window.Window' ,
listeners: {
afterlayout: function (win) {
fleXenv.fleXcrollMain (win.body.id);
}
}
}
Ext.define ('MyCustomPanel', {
extend: 'Ext.panel.Panel' ,
listeners: {
afterlayout: function (panel) {
fleXenv.fleXcrollMain (panel.body.id);
}
}
}
Now, you can instantiate MyCustomWindow and MyCustomPanel, leaving Ext.window.Window and Ext.panel.Panel unchanged.
Another way is to use WindowManager and PanelManager (this one defined by yourself):
Ext.WindowManager.register (window1);
Ext.WindowManager.register (window2);
Ext.WindowManager.register (window3);
Ext.WindowManager.each (function (win) {
win.on ('afterlayout', function (window) {
fleXenv.fleXcrollMain (window.body.id);
});
});
In this case, first you have to instantiate your windows and panels, register them to their managers and then invoke the each function as I did in the example above.

Dynamically adding html to panel

I am designing an app in sencha touch2. I have a panel object in my JS file. I need to dynamically set the text/html for this component. The store for this component is defined at the application level. Following is the thing I worked out:
Ext.define('class_name',{
....
config : {
pnlObj : null,
...
}
initialize : function() {
this.config.pnlObj = Ext.create('Ext.Panel');
var store = Ext.data.Storemanager.lookup('some_store');
store.on('load',this.loadStore,this);
this.setItems([{
//some items here
{
flex : 2,
// id : 'somepnl',
config : this.config.pnlObj
}
}]);
},
loadStore : function(store, rec) {
var text = rec.get('text');
var panel = this.config.pnlObj;
// var panel = Ext.getCmp('somepanl');
panel.setHtml(text);
}
});
When I inspect the inspect the element using Firebug console, I can find the panel added there. But I am not able to set the html dynamically. no html text is set there. I tried adding it using panel.add() & panel.setItems() method which doesn't work. If I give an id to that panel(somepanel here) and try to access it using Ext.getCmp('smpanel') then in that case it works fine. I have found that using Ext.getCmp() is not a good practice and want to avoid it as it might somewhere break my code in the future.
I guess the way I am instantiating the panel object is creating some issue. Can someone suggest the best way of doing it?
The recommended way to manipulate your components in Sencha Touch 2 is using controller, through refs and control configs. For example, your panel has a config like this: xtype:'myPanel', then in your controller:
refs: {
myPanel: 'myPanel'
}
control:{
myPanel: {
on_an_event: 'set_html_for_my_panel'
}
}
Lastly, define your function:
set_html_for_my_panel: function()
{
this.getMyPanel().setHtml('my_updated_html');
}
P/S: Behind the scene, Sencha Touch 2 uses Ext.ComponentQuery for refs in controllers

Set a default UI across all components in Sencha Touch

Within Sencha Touch, is it possible to define a default UI , like "light" or "dark", that applies to all components (unless overwritten explicitly)?
The aim is to avoid having to declare ui: "dark", or any custom UI that is made, for every element.
Cheers!
You can try this:
Ext.apply(Ext.Component.prototype, {
getUi: function() {
var defaultUi = 'light';
// value of [this.config.ui] is ignored here
// we can use something like forcedUi
return (this.forcedUi) ? this.forcedUi : defaultUi;
}
})
The disadvantage of this code is that we need to specify another variable for applying ui different from 'light' (because variable 'ui' via getUi() will always return 'light'):
...
items: [{
xtype: 'button',
forcedUi: 'dark'
}]
...
I am stuck on Touch 1.1 so sunsay's solution didn't work for me, but this did:
Ext.CustomToolbar = Ext.extend(Ext.Toolbar,
{
ui:'app'
});
Ext.reg('toolbar', Ext.CustomToolbar);
So, it's still component-by-component-type, but not component-by-component-instance. And since you can overwrite the "reg", no need for custom x-types all over the place, either.
I assume that you know about sencha touch styles and themes. Otherwise you can download a pdf file from this link which clearly describes about how to do it...
http://f.cl.ly/items/d9df79f57b67e6e876c6/SenchaTouchThemes.pdf
In it they are mentioning about scss file where you can specify the base-color, ie
$base-color: #4bb8f0 ;
$base-gradient: 'glossy';
Then run it ... you can see the toolbars and buttons created with the color and gradient you have mentioned.