Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:51:59+00:00 2026-05-23T18:51:59+00:00

I would like to calculate Total on the fly without havng to do it

  • 0

I would like to calculate Total on the fly without havng to do it in calctotal.php. In essense this is a calculated column. I thought of using some event like afterInsertRow, but even with no event it moves the column data by one because the XML file is only 3 columns instead of four. So my Total column now has the data from Notes I did add a fake column to the php file, but why should I have to do that? Thanks

url:'./calctotal',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No', 'Amount','Tax','Total'm 'Notes'],
colModel :[ 
  {name:'invid', index:'invid', width:55}, 
  {name:'amount', editable: false, index:'amount', width:80, align:'right'}, 
  {name:'tax', index:'tax', width:80, align:'right'}, 
  **{name:'total', index:'total', width:80, align:'right'},**
  {name:'notes', index:'notes', width:80, align:'left'}

],
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:52:00+00:00Added an answer on May 23, 2026 at 6:52 pm

    The bast way to implement “virtual columns” in jqGrid is the usage of the custom formatter. For example

    {name:'amount',index:'amount',width:70, formatter:'currency', align:'right'},
    {name:'tax',index:'tax',width:50, formatter:'currency', align:'right'},
    {name:'total',index:'total',width:60, align:'right',
     formatter:function(cellvalue, options, rowObject) {
         var amount = parseInt(rowObject.amount,10),
             tax = parseInt(rowObject.tax,10);
         return $.fmatter.util.NumberFormat(amount+tax,$.jgrid.formatter.currency);
     }}
    

    The main disadvantage of the usage of the custom formatter is that you use make full formatting inside. The call of the method $.fmatter.util.NumberFormat can help us to simplify the work.

    If you use remote datatype (datatype: 'xml' or datatype: 'json') the server is responsible for data sorting. So the server should be able to sort the data not only for the “real” data field but for the “virtual” columns also. We use index:'total' above. So if the user click on the header of the ‘Total’ column the sidx parameter which will be send to the server will be total. So the server should be able to produce the data sorted by the total.

    If you use local data you can use sorttype as the function to implement the sorting:

    {name:'amount',index:'amount',width:70, formatter:'currency', sorttype:'number',
     align:'right'},
    {name:'tax',index:'tax',width:50, formatter:'currency', sorttype:'number',
     align:'right'},
    {name:'total',index:'total',width:60, align:'right',
     formatter:function(cellvalue, options, rowObject) {
         var amount = parseInt(rowObject.amount,10),
             tax = parseInt(rowObject.tax,10);
         return $.fmatter.util.NumberFormat(amount+tax,$.jgrid.formatter.currency);
     },
     sorttype:function(cellvalue, rowObject) {// like for sorttype:'number',
         var amount = parseInt(rowObject.amount,10),
             tax = parseInt(rowObject.tax,10);
         return amount+tax;
     }}
    

    See the demo here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to calculate total order amount in the previous month. I got
I would like to calculate my total order amount in the previous week. I
I would like to be able to calculate the total number of bytes a
I would like to calculate a new date simply by using the build-in dateadd
I have some protein sequences. I would like to calculate the the total number
This is my code: print('What amount would you like to calculate tax for? ')
I have a listview and would like to calculate a running total of values.
I would like to calculate the similarity between users, which is reciprocal. similarity[:user1][:user2] ==
I would like to calculate a timestamp based on the input date. I would
I would like to calculate a density function of a distribution whose characteristics function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.