Exploring the power of pagination using Django and ExtJS

Extjs offers a gridpanel with pagination functionality, but I believe that the pagination only works once all the data has been received from the server (please correct me if I am mistaken). In my situation, the total amount of data from the server is 20MB, which I do not want to load in one ajax call as it can cause browser performance issues. Here is what I am looking for:

  1. Load approximately 1 MB of data at the initial page load
  2. Implement extjs pagination within this loaded data
  3. When the next button on the paging toolbar is clicked, make an ajax call to retrieve the next 1MB of data and display it in the grid
  4. Continue using extjs pagination within each subsequent 1MB chunk of data
  5. Repeat this process...

I would appreciate any suggestions on how I can achieve this, or if there are existing methods in EXTJS to handle this scenario. Thank you for your assistance.

PS: My backend server is Django

Answer №1

It appears that the pagination feature in this context operates only after receiving all data from the server.

What led you to this conclusion?

The ExtJS Grid Pagination mechanism functions by setting a specific page size (such as 100), prompting the store to request the initial 100 entries from the server. Upon clicking "next page", the subsequent 100 entries are fetched from the server, and so forth.

In order for the pagination to function correctly, the server API must comprehend the significance of startParam, pageParam, and limitParam.

Answer №2

Although it may be late, I have a solution for those seeking to implement pagination with Django and ExtJS using the "start" and "limit" pagination parameters sent by ExtJS.

def retrieveRecords(self, params):
    
    totalEntries = 0
    pageNumber = 1
    records = []
    ids = []
    
    #Initialize query object
    query = Q()

    #If there are filter criteria parameters, add them here
    if(params.get("searchStartDate")):
         startDate = datetime.strptime(params.get("searchStartDate"), '%Y-%m-%d').date()
         query &= Q(date_created__gte=startDate)     
    if(params.get("searchEndDate")):
         endDate = datetime.strptime(params.get("searchEndDate"), '%Y-%m-%d').date()
         query &= Q(date_created__lte=endDate)     
    
    # Get the total count of entries
    totalEntries = YourModel.objects.filter(query).count()

    #Retrieve primary keys as fetching all objects can impact performance
    your_model_ids_list = YourModel.objects.filter(query).order_by("-id").only('id')

    #Calculate page number based on start and limit parameters
    if(int(params.get("start")) != 0 ):
        pageNumber = (int(params.get("start")) / int(params.get("limit"))) + 1

    #Instantiate paginator with primary keys list and limit        
    paginator = Paginator(your_model_ids_list, int(params.get("limit")))

    #Get record IDs for specified page number
    recordIds = paginator.page(pageNumber)

    #Collect record IDs in an array
    for recordId in recordIds.object_list:
        ids.append(recordId.id)


    #Fetch records from model based on collected IDs
    result = YourModel.objects.filter(Q(pk__in=ids)).order_by("-id")


    #Create response object and return data
    return {'totalEntries': totalEntries, 'records': result}

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

Ways to determine cleanliness or filthiness in an Angular 5 modal form?

I have a form within a modal and I only want to submit the form if there are any changes made to the form fields. Here is a snippet of my form: HTML <form [formGroup]="productForm" *ngIf="productForm" (ngSubmit)="submitUpdatedRecord(productForm.value) ...

What is the best way to include a MongoDB match argument when it is received from the frontend, and to exclude it if it is not provided?

I'm currently working on creating an aggregation in MongoDB using NodeJS. The goal is to add an argument to the MongoDB match function if it exists when the resolver function is called. However, I'm encountering an issue where if no addition is m ...

Unveiling the Power of AngularJS for Parsing JSON Data

A list of images is being generated in a table-like structure using the code snippet below. Each image represents a cell in this table, with its ID specifying its row and column position. <ul> <li class="row"> <ul> & ...

Utilizing Queries Within Django Models

I am facing a challenge with my Django models - User_details and Monthly_payment. I want to set the status of users as Active, Expire, Soon Expire, or Deactivated based on different fields in these two models. Specifically, I am trying to achieve this us ...

Inject a snippet of temporary code at the end of the CSS file using JavaScript or JQuery

I am looking to dynamically add temporary CSS code to the end of an external CSS file or modify it using JavaScript or jQuery. For example, let's say my mystyle.css file looks like this: //mystyle.css p{color:red} Now, when a user interacts with the ...

Retrieve the current state of the toggle component by extracting its value from the HTML

I have a unique component that consists of a special switch and several other elements: <mat-slide-toggle (change)="toggle($event)" [checked]="false" attX="test"> ... </mat-slide-toggle> <p> ... </p> F ...

"Tricky HTML table layout challenge: Margins, paddings, and borders causing

Working with HTML <table cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <img src="..."> </td> </tr> </tbody> </table> Applying CSS rules * { border: none; ...

How about, "Enhance your website navigation with a sleek anchor

After many attempts to implement smooth scrolling on my Bootstrap project, I have tried numerous Youtube tutorials and Google search results without any success. The latest attempt I made was following this Stack Overflow post Smooth scrolling when clickin ...

Using jQuery to locate and substitute specific text

Here's a snippet of HTML code I'm working with for posts that have a sneak peek followed by a "Read more" button to reveal additional content. The issue arises when trying to dynamically remove the "[...]" from only the post where the button is c ...

Leverage access tokens in React.js frontend application

After successfully creating an authentication API using Nodejs, Expressjs, MongoDB, and JWT, I am now working on a small frontend application with React-js specifically for Sign-up and Sign-in functionalities. While I have managed to integrate the Sign-up ...

Switchable radio options

Currently, I am creating a form containing multiple options that are mutually exclusive. However, none of these options are mandatory. That is why I want to enable the user to uncheck a selected radio button by simply clicking on it again. This way, all th ...

Having trouble displaying specific images on React Native, how can I resolve this issue?

I am currently developing a weather application that retrieves weather information and displays it using ForecastItem components. However, I have noticed that some of the components do not display the weather image randomly. On the Home screen, I use the ...

Is there a way to trigger $q notify without initiating a $digest cycle?

Within my application, the $digest cycle typically takes around 5ms to complete. I heavily utilize $q.defer with deferred.notify throughout my codebase, but I've encountered an issue. Each time deferred.notify is triggered, it schedules a new digest c ...

Caution: Potential Unresolved Promise Rejection Detected (ID: 21) - Error: Undefined is not a valid object when trying to evaluate 'res.json'

ERROR Getting an Unhandled Promise Rejection (id: 21): TypeError: undefined is not an object (evaluating 'res.json'). Any suggestions on fixing this issue in my code? I've checked the logs for user and loggeduserobj, and they seem to be cor ...

What is the process of saving a model with @tensorflow/tfjs-node version 2?

I've been struggling with setting up the save handler to save my model. I've scoured through various platforms like stack overflow and GitHub, but haven't had any luck. Help! Any guidance would be greatly appreciated!!! :) Below is a snipp ...

The onclick handler fails to function following the injection of html using jquery AJAX

After using ajax to inject HTML into my page, the onclick handler on a specific part of that injected HTML does not seem to be functioning... Specifically, I am referring to this image... < img class="close_row" src="img/close.gif"/> In jQuery, I ...

Tips for displaying the message "{"POWER":"ON"}" within the else if statement (this.responseText == ({"POWER":"ON"})) {

Hey everyone, I'm trying to adjust the color of a button on my webpage based on the response I receive from this.responseText. I understand the JSON response, but for some reason, I can't seem to incorporate it into my code. If anyone could lend ...

jQuery Ajax Redirect Form

I am currently developing an HTML application with a form. Upon clicking the submit button, I initiate a server-side call using jquery.ajax(). However, when the server returns an exception, such as a Status Code 500, I need to display an error message on t ...

Uploading photos to Firebase storage using React Native

Could you please assist me in identifying my mistake here? I saw it being done in a video. The error message I am encountering is: TypeError: undefined is not an object (evaluating 'media.cancelled') const [isUploading, setIsUploading] = useS ...

Spring's MVC framework encountered a 400 Bad Request error when processing an

Encountering a recurring issue with receiving a 400 Bad Request error during Ajax requests. It's puzzling as to what could be causing this problem. The technologies being used include: <dependency> <groupId>org.codehaus.jackson</gr ...