How to create a displayfield in Sencha Touch

Sencha Touch has, unlike Ext JS,  no displayfield component. That is somewhat unhandy, when you are used to it. But searching on the forum of Sencha I found a satisfying solution to solve this.

Thanks to the effort of Sencha user Mike Suiter from Omaha I have put the following class definitions in my applications.

Ext.ux.DisplayField

Ext.ux.DisplayFieldComponent

How to put this in your application

In my applications root folder (apps) I have a folder called ux. In this folder I have placed all my third party components and plugins. So my app folder has a structure as shown below. It contains 2 applications: Someapp and Anotherapp. It can even be that one app is an Ext JS app and the other a Sencha Touch app.

Put the 2 components DisplayField and DisplayFieldComponent in the root of the ux folder. Now put the following in your app.js.

(line 6): Only put here the other app if you would like to share classes from that other project. If I build an Ext JS application and a tablet version using the same models and stores f.e. then I don’t define them twice. Another useful usage is that in this way you can share base classes that you use in every project. So the other app can also be a library of your most used classes for every project.

How to use it

The usage is very simple and not different to the usage of a text field. It is in fact an extension of the Ext.field.Field class.

You can change the content of the field by using the setValue method.

Don’t forget that somefield is the itemId of that field.

Below you see a sample of usage on an iPhone in a Ext.sheet component.

Sample of DisplayField in Sencha Touch

Johan van de Merwe
Dedicated to professional software development since 1985. Has worked since 1992 as IT manager in several international operating companies. Since 2007 CEO and Sencha Ext JS web application developer at Enovision GmbH.

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.