13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Ext.define('KitchenSink.view.dataview.MultiSort', {
    extend: 'Ext.panel.Panel',
 
    requires: [
        'Ext.toolbar.TextItem',
        'Ext.view.View',
        'Ext.ux.DataView.Animated'
    ],
    
    xtype: 'dataview-multisort',
    title: 'Multisort DataView',
    width: 540,
    height: 580,
    layout: 'fit',
    //<example>
    exampleDescription: [
        '<p>This example shows using multiple sorters on a Store attached to a DataView.</p>',
        '<p>We\'re also using the reorderable toolbar plugin to make it easy to reorder ',
        'the sorters with drag and drop. To change the sort order, just drag and drop the',
        '"Type" or "Name" field.</p>'
    ],
    themes: {
        classic: {
        },
        neptune: {
        }
    },
    //</example>
 
    initComponent: function() {
        this.tbar = {
            plugins: {
                xclass: 'Ext.ux.BoxReorderer',
                listeners: {
                    scope: this,
                    drop: this.updateStoreSorters
                }
            },
            defaults: {
                listeners: {
                    scope: this,
                    changeDirection: this.updateStoreSorters
                }
            },
            items: [{
                xtype: 'tbtext',
                text: 'Sort on these fields:',
                reorderable: false
            }, {
                xtype: 'dataview-multisort-sortbutton',
                text : 'Type',
                dataIndex: 'type'
            }, {
                xtype: 'dataview-multisort-sortbutton',
                text : 'Name',
                dataIndex: 'name'
            }]
        };
        
        this.items = {
            xtype: 'dataview',
            tpl: [
                '<tpl for=".">',
                    '<div class="dataview-multisort-item">',
                        (!Ext.isIE6? '<img src="resources/images/touch-icons/{thumb}" />' : 
                        '<div style="position:relative;width:74px;height:74px;'+
                                 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'resources/images/touch-icons/{thumb}\')"></div>'),
                        '<h3>{name}</h3>',
                    '</div>',
                '</tpl>'
            ],
            plugins: {
                xclass: 'Ext.ux.DataView.Animated'
            },
            itemSelector: 'div.dataview-multisort-item',
            store: Ext.create('Ext.data.Store', {
                autoLoad: true,
                sortOnLoad: true,
                fields: ['name', 'thumb', 'url', 'type'],
                proxy: {
                    type: 'ajax',
                    url : 'resources/data/sencha-touch-examples.json',
                    reader: {
                        type: 'json',
                        root: ''
                    }
                }
            })
        };
        
        this.callParent(arguments);
        this.updateStoreSorters();
    },
    
    /**
     * Returns the array of Ext.util.Sorters defined by the current toolbar button order
     * @return {Array} The sorters
     */
    getSorters: function() {
        var buttons = this.query('toolbar dataview-multisort-sortbutton'),
            sorters = [];
        Ext.Array.each(buttons, function(button) {
            sorters.push({
                property : button.getDataIndex(),
                direction: button.getDirection()
            });
        });
        
        return sorters;
    },
    
    /**
     * @private
     * Updates the DataView's Store's sorters based on the current Toolbar button configuration
     */
    updateStoreSorters: function() {
        var sorters = this.getSorters(),
            view = this.down('dataview');
 
        view.store.sort(sorters);
    }
});