简体   繁体   中英

Getting the current store - Ext JS

Good Morning SO!

I have a grid that changes stores at the click of a button.

How could I get the current store of my grid, regardless of which one is loaded?

通常grid.getStore()为您提供连接到网格的商店

How could I get the current store of my grid?

---> You would get current store using either grid.getStore() or directly as grid.store .

regardless of which one is loaded?

----> You will have only one store assigned to grid and the same store you will be assigning it to Paging Toolbar

here is the example from sencha :

 Ext.onReady(function () {
    Ext.tip.QuickTipManager.init();
    Ext.define('ForumThread', {
        extend : 'Ext.data.Model',
        fields : ['title', 'forumtitle', 'forumid', 'username', {
                name : 'replycount',
                type : 'int'
            }, {
                name : 'lastpost',
                mapping : 'lastpost',
                type : 'date',
                dateFormat : 'timestamp'
            }, 'lastposter', 'excerpt', 'threadid'],
        idProperty : 'threadid'
    });
    // ***** create the Data Store, assign variable to grid and paging toolbar ***** 
    var store = Ext.create('Ext.data.Store', {
            pageSize : 50,
            model : 'ForumThread',
            remoteSort : true,
            proxy : {
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better type: 'jsonp', url: 'http://www.sencha.com/forum/topics-browse-remote.php',
                reader : {
                    root : 'topics',
                    totalProperty : 'totalCount'
                },
                // sends single sort as multi parameter
                simpleSortMode : true
            },
            sorters : [{
                    property : 'lastpost',
                    direction : 'DESC'
                }
            ]
        });
    // pluggable renders function
    renderTopic(value, p, record) {
        return Ext.String.format('<b><a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a></b><a href="http://sencha.com/forum/forumdisplay.php?f={3}" target="_blank">{1} Forum</a>', value, record.data.forumtitle, record.getId(), record.data.forumid);
    }
    function renderLast(value, p, r) {
        return Ext.String.format('{0}<br/>by {1}', Ext.Date.dateFormat(value, 'M j, Y, g:i a'), r.get('lastposter'));
    }
    var pluginExpanded = true;
    var grid = Ext.create('Ext.grid.Panel', {
            width : 700,
            height : 500,
            title : 'ExtJS.com - Browse Forums',
            // ***** above declared store assigned to grid, same will be assigned to paging toolbar
            store : store,
            disableSelection : true,
            loadMask : true,
            viewConfig : {
                id : 'gv',
                trackOver : false,
                stripeRows : false,
                plugins : [{
                        ptype : 'preview',
                        bodyField : 'excerpt',
                        expanded : true,
                        pluginId : 'preview'
                    }
                ]
            },
            id : 'topic',
            text : "Topic",
            dataIndex : 'title',
            flex : 1,
            renderer : renderTopic,
            sortable : false
        }, {
            text : "Author",
            dataIndex : 'username',
            width : 100,
            hidden : true,
            sortable : true
        }, {
            text : "Replies",
            dataIndex : 'replycount',
            width : 70,
            align : 'right',
            sortable : true
        }, {
            id : 'last',
            text : "Last Post",
            dataIndex : 'lastpost',
            width : 150,
            renderer : renderLast,
            sortable : true
        }
            ],
            // paging bar on the bottom bbar:
            Ext.create('Ext.PagingToolbar', {
                // *********  same store which is applied to the grid
                store : store,
                displayInfo : true,
                displayMsg : 'Displaying topics {0} - {1} of {2}',
                emptyMsg : "No topics to display",
                items : ['-', {
                        text : 'Show Preview',
                        pressed : pluginExpanded,
                        enableToggle : true,
                        toggleHandler : function (btn, pressed) {
                            var preview = Ext.getCmp('gv').getPlugin('preview');
                            preview.toggleExpanded(pressed);
                        }
                    }
                ]
            }), renderTo : 'topic-grid'
 });
 // trigger the data store load
 store.loadPage(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM