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

  • Home
  • SEARCH
  • 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 7406303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:32:14+00:00 2026-05-29T05:32:14+00:00

I am using jQuery for UI and my programming language is Java. Now I

  • 0

I am using jQuery for UI and my programming language is Java. Now I want to get remote data using an Ajax call to Java servlet and get the records from remote site in sorted order with also grand total. How can I do that?

I found many examples, but that was in PHP only. I want to implement it in Java, and I am not able to understand PHP.

Example which I found is as below.

JavaScript code

jQuery("#48remote2").jqGrid({
    url:'server.php?q=2',
    datatype: "json",
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:55, editable:true, sorttype:'int',summaryType:'count', summaryTpl : '({0}) total'},
        {name:'invdate',index:'invdate', width:90, sorttype:'date', formatter:'date', datefmt:'d/m/Y'},
        {name:'name',index:'name', width:100},
        {name:'amount',index:'amount', width:80, align:"right", sorttype:'number',formatter:'number',summaryType:'sum'},
        {name:'tax',index:'tax', width:80, align:"right",sorttype:'number',formatter:'number',summaryType:'sum'},
        {name:'total',index:'total', width:80,align:"right",sorttype:'number',formatter:'number', summaryType:'sum'},
        {name:'note',index:'note', width:150, sortable:false,editable:true}
    ],
    rowNum:10,
    rowList:[10,20,30],
    height: 'auto',
    pager: '#p48remote2',
    sortname: 'invdate',
    viewrecords: true,
    sortorder: "desc",
    caption:"Grouping with remote data",
    grouping: true,
       groupingView : {
           groupField : ['name'],
           groupColumnShow : [true],
           groupText : ['<b>{0}</b>'],
           groupCollapse : false,
        groupOrder: ['asc'],
        groupSummary : [true],
        groupDataSorted : true
       },
    footerrow: true,
    userDataOnFooter: true
});
jQuery("#48remote2").jqGrid('navGrid','#p48remote',{add:false,edit:false,del:false});

And PHP code is as below,

PHP MySQL code

examp = $_REQUEST["q"]; //Query number

$page = $_REQUEST['page'];  // Get the requested page
$limit = $_REQUEST['rows']; // Get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx'];  // Get index row - i.e. user click to sort
$sord = $_REQUEST['sord'];  // Get the direction
if(!$sidx) $sidx =1;
...

$result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id".$wh);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
    $total_pages = ceil($count/$limit);
}
else {
    $total_pages = 0;
}
if ($page > $total_pages)
    $page=$total_pages;
$start = $limit*$page - $limit; // Do not put $limit*($page - 1)
if ($start<0)
    $start = 0;
$SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id".$wh." ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Could not execute query.".mysql_error());
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0; $amttot=0; $taxtot=0; $total=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $amttot += $row[amount];
    $taxtot += $row[tax];
    $total += $row[total];
    $responce->rows[$i]['id']=$row[id];
    $responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
    $i++;
}
$responce->userdata['amount'] = $amttot;
$responce->userdata['tax'] = $taxtot;
$responce->userdata['total'] = $total;
$responce->userdata['name'] = 'Totals:';
echo json_encode($responce);

But I am not able to understand the code in PHP. How can I do that?

  • 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-29T05:32:15+00:00Added an answer on May 29, 2026 at 5:32 am

    If I understand you correct you need include summary line in the bottom of the grid. To do this you don’t need the grouping part from the posted example. The only parameters which are important in your case are:

    footerrow: true,
    userDataOnFooter: true
    

    If you use both from the jqGrid options you need just calculate the sum for the columns where you need it has and include "userdata" part in the JSON which produce the servlet. See here, here and here for more information.

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

Sidebar

Related Questions

Using jQuery helps in functional programming? I am using jQuery and want to do
I am trying to remove text from a dropdown menu using a Jquery plugin
I'm using jQuery and AJAX to validate my form when someone creates a new
I have little programming experience so the jump from basic php to using classes,
I'm using jQuery UI Tabs with Ajax and I am getting an error: Failed
I'm using the following jQuery code to collapse lists from left to right: (See
I have some HTML I'm working on using programming from a CMS I didn't
I have been using asp.net programming just from few months and I have to
Using jQuery , how can I dynamically set the size attribute of a select
Using jQuery, how do you bind a click event to a table cell (below,

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.