Determine the Total of a Column in jqgrid

Hey there, I'm looking for a way to calculate the total sum of the "montant" column in my jqgrid and then display it below the grid as "Total: *total amount*". Here is the code for my grid:

<sjg:grid id="gridtable"
        caption="Quittance Payée"
        dataType="json"
        width="755"
        href="%{remoteurl}"
        pager="true"
        gridModel="gridModel"
        rowList="5,10,15,20"
        rowNum="5"
        rownumbers="true"

        >

    <sjg:gridColumn name="entreprise" index="entreprise" title="Entreprise"/>
    <sjg:gridColumn name="nature" index="nature" title="Nature" sortable="false"/>
    <sjg:gridColumn name="numero" index="numero" title="Numero" sortable="false"/>
    <sjg:gridColumn name="montant" index="montant" title="Montant" sortable="false"/>

</sjg:grid>

Any suggestions or ideas on how to achieve this? :)

Answer №1

Using the latest jqGrid update allows you to easily achieve this:

You can accomplish this task by utilizing the getCol method.

Start by initializing a variable to store the sum:

var sum = jQuery("#gridtable").getCol('montant', false, sum);

That's it. The sum variable will now contain the total sum of the 'montant' column. For more details on the additional parameters for the getCol method, visit here.

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

JavaScript: A step-by-step guide to extracting the file name and content from a base64 encoded CSV

I have a base64 string that was generated by encoding a csv file, const base64 = 'LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTExNDc2MDgwNjM5MTM4ODk4MTc2NTYwNA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmaWxlIjsgZmlsZW5hbWU9ImNoYXJ0T2ZBY2NvdW50LmNzd ...

jQuery load() function triggers unexpected error in jQuery plugin

Here is the current structure of my page: <body> <div id="menuBar"> </div> <canvas id="myCanvas" width="700" height="700" style="border:1px solid #000000;"></canvas> </body> <script src="../Scripts/jQuery.mazeBo ...

Optimizing Performance in THREE .JS Raycasting

I am attempting to determine the shortest distance from a point to a large, intricate Mesh along a plane within a specific direction range: for (var zDown in verticalDistances) { var myIntersect = {}; for (var theta = Math.PI / 2 - 0.5; theta &l ...

The element is not positioned correctly due to the absolute positioning

This is my first attempt at creating a jQuery plugin and I have almost got it working correctly. You can view the example here. I've been struggling for days to position an element as desired. The goal is to display some text with an optional downwar ...

Regardless of the circumstances, the Node.js PATCH request will always run

Apologies if the title is unclear, I struggled with how to phrase it. I encountered an issue with a PATCH request designed to update a value in my database: although it returns a "working" status (200), the actual update does not occur. I have a .route(&ap ...

Why does wp-ajax return 0 on the front end but work perfectly in the admin area?

After implementing these functions in my plugin, they are functioning properly in the backend. However, I am encountering a response of 0 in the frontend. I have tried copying and pasting the same code, and have also attempted using both admin_enqueue_scri ...

Troubleshooting: Why jQuery is Not Functioning Properly in Conjunction

Currently, I am in the process of developing a friend search feature. This function operates effectively; upon entering a name in the search bar, individual user profiles appear in separate div containers with their respective images and names. Each profil ...

Refreshing ApolloClient headers following a successful Firebase authentication

I am encountering an issue while trying to send an authorization header with a graphql request when a user signs up using my React app. Here is the flow: User signs up with Firebase, and the React app receives an id token. User is then redirected to ...

Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using: #rij1 .content-overlayz, #rij1 .content-details { animation-duration: 2s; animation-name: stepped-pulse; animation-iterati ...

The SSE emitter sends out multiple signals, but occasionally the browser fails to receive them

When setting up an event emitter in a node.js/express application, I noticed that the events emitted are sometimes received multiple times by the front-end listener. Although I can confirm that emit is only called once, the same event gets emitted up to 4 ...

Is there a way to verify if the email entered into the input field is included in the list provided below?

Whenever an email is entered into the text box, a validation message should appear next to the input field. The inputted email should be checked against the list of emails below, and if it exists, an error message needs to be displayed. I need assistance w ...

"Is it possible in Typescript to set the parameters of a returning function as required or optional depending on the parameters of the current

I am currently exploring Typescript and attempting to replicate the functionality of styled-components on a smaller scale. Specifically, I want to make children required if the user passes in 'true' for the children parameter in createStyledCompo ...

Is it possible for a draggable position:absolute div to shrink once it reaches the edge of a position:relative div

I am facing an issue with draggable divs that have position:absolute set inside a position:relative parent div. The problem occurs when I drag the divs to the edge of the parent container, causing them to shrink in size. I need the draggable divs to mainta ...

A guide on incorporating Vue.js into a Hexo static site generator

Exploring the use of vue.js within my hexo theme has sparked my interest. Can anyone guide me on how to compile my .vue files for both development and production environments? It's worth mentioning that I intend for vue.js to operate on the client sid ...

jQuery's feature to select all elements except one and its children appears to be malfunctioning in Safari

My goal is fairly simple. I want to make the entire section clickable, except for the span and anything beneath it, so that the link redirects elsewhere. <section id="id" class="message"> <div class="message_body"> <font color="color"> ...

Utilizing Ionic to seamlessly integrate Firebase into a factory, maintaining separation of controllers and services within distinct files

I'm struggling with setting up a firebase factory for use in my controllers. Currently, this is how my code appears: index.html ... <!-- integrating firebase --> <script src="lib/firebase/firebase.js"></script> <script src="lib/ ...

Steps for inserting a clickable phone number link within innerHTML1. First, create an

I've been trying to include a specific phone number using the <a href> tag within the innerHTML. I attempted using both double and single quotes. In the first case, nothing happens at all. In the second case, although the phone number appears, ...

I am facing issues with installing React Router on my Windows device

After running the command to install react-router, this is the output from my prompt window: npm install --save react-router The prompt window shows several warnings and optional dependencies: npm WARN @babel/core requires a peer of @babel/core@^7.13 ...

I am still receiving an empty dropdown value despite implementing ng-selected

I am having issues with using ng-selected to retrieve the selected value from a dropdown. Instead of displaying the selected value, it appears blank. Here is the code snippet I have tried: <div> <select id="user_org" ng-model="selectedorg.all ...

When implementing ReplaySubject in Angular for a PUT request, the issue of data loss arises

I seem to be encountering a problem with the ReplaySubject. I can't quite pinpoint what I've done wrong, but the issue is that whenever I make a change and save it in the backend, the ReplaySubject fetches new data but fails to display it on the ...