1. 程式人生 > >ExtJS用Grid顯示資料後如何自動選取第一條記錄

ExtJS用Grid顯示資料後如何自動選取第一條記錄

       用Grid顯示資料後,如何讓系統自動選取第一條記錄呢?在顯示Grid時由於其Store正在loading,沒法在Grid選取第一條記錄,因為還沒有記錄,所以應在其Store進行操作。

檢視Ext.data.Store的load()方法如下:

([options])

Loads data into the Store via the configuredproxy. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required. Example usage:

store.load({
    scope:this,
    callback:function(records, operation, success){// the operation object// contains all of the details of the load operation
        console.log(records);}});
有一個callback函式,可以該回調函式中執行Grid選取第一條記錄的操作。

    Store.load({
        callback: function(rec, oper, success){
            if(success){
                Ext.getCmp('Gridid').getSelectionModel().select(0,true);


            }
        }
    });