Tips for determining which site was accessed

My store is linked to a grid and when it loads, it has multiple pages. Now, I need to display the page that contains a specific value. To achieve this, I make use of

store.load({params: {'file': 'file33939'}});
. Despite not knowing the exact page number at this point, the response typically looks like this:

{
  "files":[{"id":"33939", "name": "file33939"}, /* ... */],
  "total": 1000,
  "page": 13
}

The grid correctly shows the data for the page that contains 'file33939'. However, the paging toolbar, grid's row numberer, and store.indexOfTotal() all act as if the first page was loaded instead of page 13.

How can I inform the store that the recently loaded page is actually page 13?

Answer №1

If you want to switch the displayed page, avoid using store.load(). Instead, you need to determine the appropriate page number for the data (possibly by querying the server with an ajax request) and then use pagingtoolbar.move(pageNumber) to update the page. This ensures that your pagingtoolbar, grid, and store all stay synchronized.

Answer №2

I have discovered a viable solution that may not be the most elegant, but it gets the job done.

Upon examining the sencha code, I noticed that both the pagingtoolbar and store.indexOfTotal() were utilizing record.index, which was causing issues in my scenario where it was set as if the first page was already loaded. This setting of record.index occurs within the store.loadRecords function:

loadRecords: function(records, options) {
    // ...
    //FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.
    for (; i < length; i++) {
        if (options.start !== undefined) {
            records[i].index = options.start + i;

        }
    // ...
},

The "FIXME" comment was present in the code and is not an addition from me.

An ideal resolution would involve finding an event triggered after the response is received but before calling loadRecords, allowing for the override of options within the handler. Unfortunately, such an event has not been found yet.

However, it is always possible to override loadRecords:

Ext.define('MyApp.store.MyStore', {
    extend          : 'Ext.data.Store',
    // ...
    loadRecords     : function(records, options) {
        if (this.proxy.reader.rawData.page) {
            var page = this.proxy.reader.rawData.page;

            // Adjusting for pagingtoolbar
            this.currentPage = page;

            // Ensuring proper index behavior for rownumberer
            options.page = page;
            options.start = (page-1)*options.limit;
        }
        this.callParent(arguments);
    },
    // ...
});

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

The content of xmlhttp.responseText is not being displayed in the innerHTML

As part of my ongoing effort to enhance my understanding of Ajax for work purposes, I have been following the W3Schools tutorial and experimenting with my Apache2 server. In this process, I have placed a file named ajax_info.txt on the server (in /var/www ...

How can I efficiently iterate through the array of index IDs and then iterate individually through the communes, categories, and locations?

Currently, I am developing a nodejs typescript API where I am retrieving an array of objects using a map loop. The data for "communes", "category", and "location" is fetched from another API function based on the issuerId. However, I am facing issues with ...

Maintain Angular Dropdown Menu Open Across Page Refresh

I am currently working on an HTML/Typescript view that is connected to a SQL Database. Whenever there are changes made to the database, the entire webpage reloads. The issue we are facing is that we have dropdown menus on the page that clients want to rema ...

Looping through objects and updating state based on a filter condition

Within my React state, there exists an array of objects similar to the following: timers: { id:"-LL-YVYNC_BGirSn1Ydu" title: "Project Title" project: "Project Name", elapsed: 0, runningSince: 0, }, { id:"-LL-YVYNC_BGirSn1Ydu-2", ...

Customizing the Image Insert Dialog in Pagedown Editor

I've developed a custom insertImageDialog hook to enable file uploads directly within the editor. $('div#insertImageDialog input[type=file]').ajaxfileupload({ action: $file.attr('data-action'), ...

Oops! Looks like there was an error: $http is not defined

I'm facing a challenge with implementing $http in the AngularJS framework. I've gone through various other resources on this issue, but I can't seem to figure out what I'm doing incorrectly. Any assistance would be highly appreciated. T ...

What is the process for including a checkbox with a label in Card Media?

I attempted to create this feature using code. However, I encountered an issue where the CardMedia and the checkbox would not align properly, resulting in a lack of responsiveness. <Card> <CardMedia ...

Angular ngStyle Parsing Issue: Encountered an unexpected symbol [ when an identifier or keyword was expected

Is there a way to pass a dynamic string using the fieldName to retrieve an attribute from the item object without encountering syntax errors in older versions of Angular? Here is a simple example to illustrate the issue. While this code works fine with ang ...

External vendor scripts such as JavaScript and jQuery are not functioning properly after being rendered in a ReactJS environment

I am currently developing a frontend web app using ReactJS. I obtained a template from W3layout that is built with HTML5, CSS3, and custom JS files, along with various third-party/vendor plugins like nice-select, bootstrap, slik, owl-carousel, etc. Despit ...

What is the best way to send variables to a jQuery function?

I'm trying to create a form where I can hide unnecessary lines by toggling them with buttons using jQuery. I've managed to start working on a page, but I'm concerned about having to write a separate function for each button, which could beco ...

Modifying the external DOM with Angular Elements and WebComponents

Summary: When deleting the DOM Element of a custom Element created with Angular Elements, it causes sub-routers to fail loading components. You can find the code on Github. Unfortunately, I wasn't able to generate a stackblitz version. However, you ...

changing the value of a jQuery variable when an event occurs

Currently, I am working on an interactive jQuery experience where I want my character to navigate through multiple rooms. $(document).keydown(function(e) { switch (e.which) { case 39: $("#barry").attr("src", "img/characters/BarryBa ...

scope.$digest completes before triggering scope.$watch in Karma unit tests

I am interested in testing this specific directive: .directive('uniqueDirective', function () { return { restrict: 'A', scope: { uniqueDirective: '@', tooltip: '@', placement: '@&apo ...

Executing Java functionalities within JavaScript

Differences in results between Java and Javascript can be observed when working with large integers. For example: getCode(1747,1763,-268087281,348400) in Java returns 1921968083, while in Javascript it returns 2.510115715670451e+22. Is there a way to ach ...

Explore Youtube to find the most popular video IDs

Is it possible for me to use a string to search YouTube and retrieve the id for the top video in the search results? I want to be able to play that video directly on my website. All I have is the URL for the search: youtube_url/results?search_query=thevid ...

Finding curly brackets and commas using regular expressions

Imagine a lengthy JSON string. I am aiming to identify the following section using a regular expression: }, { "@context" My current expression is yielding two results instead of one. The only variance lies in the braces with the comma preced ...

Solving the error message: "Objects cannot be used as a React child (found: object with keys {})"

I am currently in the process of developing a full stack website that utilizes React, Express, Sequelize, and mySQL. The site is operational with features like registration and login implemented successfully. However, I encountered an issue when trying to ...

Quantifying the passage of time for data entry

Looking to create a quiz form where I can track how long it takes users to input/select answers. I attempted the following code but the timing seems off: $('input, select').on('focus', function(event) { el = $(this); name ...

The JavaScript indexOf method in an unordered list incorrectly returns the index of a specific event

Looking to retrieve the index number of an 'li' element within a 'ul' from the HTML structure. I attempted to convert the 'ul' into a list and access its children using: [...ul.children] However, upon targeting any of the chi ...

Utilizing Material UI Grid spacing in ReactJS

I'm encountering an issue with Material UI grid. Whenever I increase the spacing above 0, the Grid does not fit the screen properly and a bottom slider is visible, allowing me to move the page horizontally slightly. Here is the simplified code snippe ...