What is the best way to regain grid focus following a data reload in ExtJS?

Within my ExtJS view, there is a grid where users can select an entry along with a panel displaying details about the selected row. However, every time a different row is chosen, the view is reloaded causing the grid to lose focus for keyboard navigation.

I am looking for a solution to reload the grid store data while maintaining input focus on the grid. Although my model specifies idProperty and correctly selects the row, the column selection and input focus are lost during the reload process. I am currently using ExtJS v7.3.0.55 with the Classic Triton theme.

For example,

To demonstrate this issue, extend the code within the existing Grid with JSON Store Sencha Fiddle by implementing a data model and adding a grid event listener:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        // Custom data model with 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',
                url: 'simpsons.json', // Load data from ./simpsons.json in the fiddle ./Data folder

                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'
            }],

            listeners: {
                select: function (sender) {
                    console.log('grid selection update');
                    var record = sender.getSelected(); // Get selected record
                    var store = sender.getStore();
                    store.load(); // Reload store data
                    sender.setSelected(record); // Restore selected row
                }   
            }
        });
    }
});

Answer №1

Remember to place the chosen item in the store's load handler:

Ext.create('Ext.grid.Panel', {
    renderTo: Ext.getBody(),
    height: 300,
    width: "100%",
    title: 'Family Members',

    // Using Named Store
    store: 'familyStore',

    // Load the content
    autoLoad: true,

    columns: [{
        text: 'Name',
        dataIndex: 'name'
    }, {
        text: 'Email Address',
        dataIndex: 'email',
        flex: 1
    }, {
        text: 'Phone Number',
        dataIndex: 'phone'
    }],
    listeners: {
        select: function (chosenRowModel, pickedRecord, chosenIndex) {
            var store = chosenRowModel.getStore();
            store.on('load', function(store) {
                chosenRowModel.select(chosenIndex, true, true);
            }, this, {
                single: true
            })
            store.load();
        }
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Minimize the number of clicks needed to navigate using the HTML/JavaScript navigation

On my website, I have a navigation bar that changes the contents of a div when a user clicks on an item. However, if the user clicks multiple times in quick succession, the content changes too many times. I want to ensure that the content only changes once ...

Unlock the capability to automatically swipe on a React Native TextInput Carousel while the user types

My challenge involves setting up a carousel with either Flatlist or ScrollView (I have tested both options). This Carousel consists of multiple TextInputs. The goal is to achieve the following: There are 4 TextInputs. When the user enters 6 digits in the ...

Update Json information within VueJsonCSV and VueJS component

I'm currently using the VueJsonCSV component to export data to a CSV file. The values being exported are retrieved from the Vuex Store. <template> <v-btn depressed> <download-csv :data="json_data"> Export Files </downl ...

Access the child component within an @ChildComponent directive in Angular

Is it possible to retrieve child components of another component? For instance, consider the following QueryList: @ContentChildren(SysColumn) syscolumns: QueryList<SysColumn>; This QueryList will contain all instances of the SysColumns class, which ...

Tips on arranging an array based on dates and data in JavaScript?

I have an array with dates and other data that I need to sort based on the dates. I'm unsure of how to go about this. Can someone please assist me? Here is the array in question: 0:{_id: "01-11-2017", CommentCount: 221, Likecount: 141, Followcount: ...

How come React.js is not displaying images from local URLs?

In my React application, there is a form where users can submit an image file. To store the path of the submitted image locally for browser access, I utilized URL.createObjectURL to generate a URL for the file. Here is the code snippet: handleImageChange(e ...

Check if the data-indices of several div elements are in sequential order using a jQuery function

Is there a way to implement a function in jQuery-ui that checks the order of div elements with data-index when a submit button is pressed? I have set up a sortable feature using jQuery-ui, allowing users to rearrange the order of the divs. Here is an exam ...

Is there a way to incorporate locales in calculations involving percentages?

Given the number 4030.146852312 I want to retrieve the four decimal places from this number, resulting in: 4030.1468 Furthermore, I need to format this number according to the specified locale. For example: 4.030,1468 What is the best way to achieve thi ...

Transform a string into an array using JavaScript

Currently, I am dealing with an array: itemSku = ["MY_SERVICE","SKU_A","SKU_B"]; When passing this value to a component in Angular, the type of itemSku is being identified as a string. This prevents me from performing array operations on it. console.log ...

The `arrangeComplete` event in jQuery Isotope is failing to trigger

Here is my jQuery code utilizing the Isotope plugin: $(document).ready(function() { /** * Set up Isotope */ var $grid = $('.grid').isotope({ "itemSelector": ".grid-item", layoutMode: 'masonry', ...

Reinvent the AJAX functionality

Is there a way to create a custom function that changes the default ajax functionality? I currently have this ajax function implemented: $.ajax({ type: "POST", url: "http://" + document.location.host + '/userajax', data: 'type= ...

Looking to incorporate multiple accordion drop down menus on your website? Utilize a combination of HTML, CSS, and JavaScript to

I am experiencing a challenge with implementing multiple accordion menus on my website. Whenever I attempt to duplicate the code, the new accordion menu appears but clicking on the first bar simply scrolls me back to the top of the webpage. Below is the H ...

What is the best way to use jQuery to integrate the post and get methods?

I have a couple of different jQuery functions: one for getting data and another for posting data. First, I use the get method to retrieve data and then I post my data using the post method. Now, I am curious about how I can combine these two functions. ...

Troubleshooting: How to resolve the issue of receiving undefined values when passing API data to a child component with Axios in React

I am encountering difficulties in retrieving data that I pass to a child component. The issue may be related to the Promise not being resolved at the time of access, but I am unsure how to address it. My goal is to ensure that the data is fully retrieved f ...

What is the best way to align a modal with a layout when it appears far down the components hierarchy?

Struggling with creating a React modal and facing some issues. Let's consider the structure below: React structure <ComponentUsingModal> <Left> <ButtonToActivateModal> ... </ButtonToActivateModa ...

Tips for adjusting date formatting to suit different languages

Currently, I am working with the English locale of en-US and the French locale of fr-CA. Is there a way to convert an English date format like 05/31/2018 to a French date format like 31/05/2018? ...

Vue is having trouble loading dynamic src files, and the require function isn't functioning properly

I'm facing an issue with displaying a dynamic image. When I use the following code: <img :src="src" alt="img"> It doesn't seem to work. However, it works perfectly fine when I use: <img src="../assets/img/banana ...

What is the ideal JavaScript framework for implementing drag-and-drop, resize, and rotation features?

I am planning to create a web application that involves images and text with user handle functionalities such as drag-and-drop, resizing, and rotating. Although I have tried using JQuery UI js to implement drag-and-drop, rotate, and resize, I have encount ...

An effective method for converting a string into a two-dimensional array using JavaScript

One challenge I am facing is checking from a string if a specific fruit has the correct amount on a given date. I've managed to achieve this by converting the string into a 2D array and iterating over the columns. While this method works, I can't ...

Ways to troubleshoot opencv.js generating random values when applying cv.threshold

Whenever I choose an image and use cv.threshold, it outputs a strange number 6620912 The number seems to change at times https://i.sstatic.net/Tp9LP.png 6620912 Promise.catch (async) (anonymous) @ App.tsx:49 commitHookEffectListMount @ react-dom_client ...