亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ExtJS 數據重新加載后如何恢復網格焦點?

ExtJS 數據重新加載后如何恢復網格焦點?

達令說 2023-09-14 22:05:39
我在 ExtJS 中有一個視圖,其中包含一個網格,用戶可以在其中選擇一個條目以及一些包含當前所選行詳細信息的面板。每次選擇另一行時,都會重新加載視圖,這會導致網格失去鍵盤導航的輸入焦點。如何重新加載網格存儲數據并使輸入焦點保持在網格上?我的模型定義了idProperty,因此選擇了正確的行,但列選擇和輸入焦點丟失了。我正在使用 ExtJS v7.3.0.55 和 Classic Triton 主題。例子使用 JSON Store Sencha Fiddle 和數據模型和一些網格事件監聽器擴展現有網格中的代碼以重現該問題:Ext.application({    name: 'Fiddle',    launch: function () {        // My data model with custom ID field        Ext.define('User', {            extend: 'Ext.data.Model',            fields: [                {name: 'name',  type: 'string'},                {name: 'email', type: 'string'},                {name: 'phone', type: 'string'},            ],            idProperty: 'email',        });        Ext.create('Ext.data.Store', {            storeId: 'simpsonsStore',            model: 'User',            proxy: {                type: 'ajax',                // Loading data from ./simpsons.json in the fiddle ./Data folder.                url: 'simpsons.json',                reader: {                    type: 'json',                    rootProperty: 'items'                }            }        });        Ext.create('Ext.grid.Panel', {            renderTo: Ext.getBody(),            height: 300,            width: "100%",            title: 'Simpsons',            store: 'simpsonsStore',            autoLoad: true,            columns: [{                text: 'Name',                dataIndex: 'name'            }, {                text: 'Email',                dataIndex: 'email',                flex: 1            }, {                text: 'Phone',                dataIndex: 'phone'            }],
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

嘗試將選擇放入商店的加載處理程序中:


Ext.create('Ext.grid.Panel', {

    renderTo: Ext.getBody(),

    height: 300,

    width: "100%",

    title: 'Simpsons',


    // Using Named Store

    store: 'simpsonsStore',


    // Load the data

    autoLoad: true,


    columns: [{

        text: 'Name',

        dataIndex: 'name'

    }, {

        text: 'Email',

        dataIndex: 'email',

        flex: 1

    }, {

        text: 'Phone',

        dataIndex: 'phone'

    }],

    listeners: {

        select: function (selectionRowModel, selectedRecord, selectedIndex) {

            var store = selectionRowModel.getStore();

            store.on('load', function(store) {

                selectionRowModel.select(selectedIndex, true, true);

            }, this, {

                single: true

            })

            store.load();

        }

    }

});


查看完整回答
反對 回復 2023-09-14
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號