Ext.dataview.DataView and setEmptyText

I’m currently developing a Sencha Touch application and therefore I use Sencha Touch Beta2.

I had to change the emptyText property of a Ext.dataview.List via setEmptyText() and ran into a little bug which adds another emptyTextCmp component inside the list’s element rather than update the existing one.

So I came up with an override for this. maybe this helps someone out there too.

The function code we are going to override is Ext.dataview.Dataview#updateEmptyText:

Original function code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
updateEmptyText: function(newEmptyText) {
        var me = this;
        if (newEmptyText) {
            me.emptyTextCmp = me.add({
                xtype: 'component',
                cls: me.getBaseCls() + '-emptytext',
                html: newEmptyText,
                hidden: true
            });
        }
        else if (me.emptyTextCmp) {
            me.remove(me.emptyTextCmp, true);
            delete me.emptyTextCmp;
        }
    }

Override:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Ext.define('My.override.of.dataview.DataView', {
    override: 'Ext.dataview.DataView',
   
    updateEmptyText: function(newEmptyText){
        var me = this;
        if (newEmptyText) {
            if (me.emptyTextCmp){
                me.emptyTextCmp.setHtml(newEmptyText);
            } else {
                me.emptyTextCmp = me.add({
                    xtype: 'component',
                    cls: me.getBaseCls() + '-emptytext',
                    html: newEmptyText,
                    hidden: true
                });
            }
        } else if (me.emptyTextCmp) {
            me.remove(me.emptyTextCmp, true);
            delete me.emptyTextCmp;
        }
    }
});