Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
how can I have the total (footerData)?
19/01/2010
23:51
Avatar
a6andrea
Member
Members
Forum Posts: 9
Member Since:
27/12/2009
sp_UserOfflineSmall Offline

Hello to everyone, this is my code:

jQuery(document).ready(function(){
  jQuery("#list").jqGrid({
    url:'example.php',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['cod', 'pie', 'p.v. ie', 'fattura vendita', 'p', 'i', 'data fattura', 'note'],
    colModel :[
      {name:'cod', index:'cod', sortable: false, resizable: false},
      {name:'pie', index:'pie', sortable: false, resizable: false},
      {name:'pvie', index:'pvie', sortable: false, resizable: false},
      {name:'fattura_vendita', index:'fattura_vendita', sortable: true, resizable: false},
      {name:'p', index:'p', sortable: false, resizable: false},
      {name:'v', index:'v', sortable: false, resizable: false},
      {name:'data_fattura', index:'data_fattura', sortable: true, resizable: false},
      {name:'note', index:'note', sortable: false, resizable: false}
    ],
    footerrow: true,
    userDataOnFooter: true,
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'data_fattura',
    sortorder: 'desc',
    viewrecords: true,
    autowidth: true,
    height: '100%',
    caption: 'La mia tabella'
  });
});

I want to have the SUM of the column "pie": the word "total" at the footer of "cod" column, and the SUM of "pie" at the footer of "pie" column

How i have to use the method footerData ??

jQuery("#list").jqGrid('footerData', set, ........);

Sorry for my english and thank You every one for help!!

Andrea

20/01/2010
11:47
Avatar
jogep
Germany
Member
Members
Forum Posts: 23
Member Since:
14/01/2010
sp_UserOfflineSmall Offline

in your json result you must return an array userdata.

$responce->userdata['pie'] = $piesum;

json_encode($responce);

20/01/2010
21:37
Avatar
a6andrea
Member
Members
Forum Posts: 9
Member Since:
27/12/2009
sp_UserOfflineSmall Offline

this the last part of expamle.php:

<?php

....

...

// the actual query for the grid data
$SQL = "SELECT * , date_format(data_fattura, '%d-%m-%Y') AS data_fattura_l FROM articoli ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
 
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$responce->userdata['pie'] = $piesum;
$i=0;

while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
    $responce->rows[$i]['id']=$row[id];
    $responce->rows[$i]['cell']=array("$row[codice] - $row[descrizione]",
                                      $row[prezzoie],
                                      $row[prezzoiev],
                                      $row[fattura_vendita],
                                      $row[id_pagato],
                                      $row[id_incassato],
                                      $row[data_fattura_l],
                                      $row[note]);
    $i++;
}
echo json_encode($responce);

?>

It doesn't work... sorry but I'm a news user can you explain me?

thanks a lot!

Andrea

21/01/2010
04:28
Avatar
Jayesh
Guest
Guests

use like below

jQuery(”#list”).footerData('set',{cod:'Total',pie:sum});  -- where sum is a variable holding the total

22/01/2010
16:27
Avatar
a6andrea
Member
Members
Forum Posts: 9
Member Since:
27/12/2009
sp_UserOfflineSmall Offline

This is the script in the file html:

<script type="text/javascript">
jQuery(document).ready(function(){
  jQuery("#list").jqGrid({
    url:'example.php',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['cod - desc', 'pie', 'p.v. ie', 'fattura vendita', 'p', 'i', 'data fattura', 'note'],
    colModel :[
      {name:'cod', index:'cod', sortable: false, resizable: false},
      {name:'pie', index:'pie', sortable: false, resizable: false},
      {name:'pvie', index:'pvie', sortable: false, resizable: false},
      {name:'fattura_vendita', index:'fattura_vendita', sortable: true, resizable: false},
      {name:'p', index:'p', sortable: false, resizable: false},
      {name:'v', index:'v', sortable: false, resizable: false},
      {name:'data_fattura', index:'data_fattura', sortable: true, resizable: false},
      {name:'note', index:'note', sortable: false, resizable: false}
    ],

    footerrow: true,
    userDataOnFooter: true,
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'data_fattura',
    sortorder: 'desc',
    viewrecords: true,
    autowidth: true,
    height: '100%',
    caption: 'La mia tabella'
  });
});
jQuery("#list").footerData('set',{cod:'Total',pie:sum});
</script>

and this is the file example.php:

<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password
include("_conn.db.inc.php");
 
// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
$page = $_GET['page'];
 
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_GET['rows'];
 
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
 
// sorting order - at first time sortorder
$sord = $_GET['sord'];
 
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;
 
// calculate the number of rows for the query. We need this for paging the result
$sql="SELECT COUNT(*) AS count FROM articoli";
$result = mysql_query($sql,$db) or die(mysql_error());
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
 
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
              $total_pages = ceil($count/$limit);
} else {
              $total_pages = 0;
}
 
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
 
// calculate the starting position of the rows
$start = $limit*$page - $limit;
 
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
 
// the actual query for the grid data
$SQL = "SELECT * , date_format(data_fattura, '%d-%m-%Y') AS data_fattura_l FROM articoli ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error());
 
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$responce->userdata['pie'] = $piesum;
$i=0;

while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
    $responce->rows[$i]['id']=$row[id];
    $responce->rows[$i]['cell']=array("$row[codice] - $row[descrizione]",
                                      $row[prezzoie],
                                      $row[prezzoiev],
                                      $row[fattura_vendita],
                                      $row[id_pagato],
                                      $row[id_incassato],
                                      $row[data_fattura_l],
                                      $row[note]);
    $i++;
}
echo json_encode($responce);
?>

but the total isn't print...
Where is the error?

Thanks for all !

Andrea

24/01/2010
15:24
Avatar
a6andrea
Member
Members
Forum Posts: 9
Member Since:
27/12/2009
sp_UserOfflineSmall Offline

up !

24/01/2010
18:01
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Where is the value for $piesum;

Just test this way:

$responce->userdata['pie'] = 1234;

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

25/01/2010
00:23
Avatar
newperson
Member
Members
Forum Posts: 27
Member Since:
28/12/2009
sp_UserOfflineSmall Offline

Andrea you are doing it wrong. Let me see if I can help.

  $result = mysql_query("SELECT COUNT(DISTINCT store_number) AS storecount from store_item_monitor);
  $row = mysql_fetch_array($result,MYSQL_ASSOC);
  $storecount = $row['storecount'];
  $responce->stores = $storecount;

//'Store' is the name in your ColModel below syntax appends the results of the mysql syntax as a footer.
  $responce->userdata['Store'] = 'Total:'.$storecount;

http://gyazo.com/d5bf7889b1fb673e9c83d7541407cb4c.png

Here you can view what my grid looks like and it should give you a good idea on what to do next with the information I gave you which is specific to my grid =)

Enjoy!

26/01/2010
22:53
Avatar
a6andrea
Member
Members
Forum Posts: 9
Member Since:
27/12/2009
sp_UserOfflineSmall Offline

@ tony and newperson :

Thank You very much !!!!
Now I have my grid with the total at the footerrow !!

Really, Thank You a lot !!!

Andrea

01/02/2010
06:43
Avatar
aznan
Member
Members
Forum Posts: 32
Member Since:
14/01/2010
sp_UserOfflineSmall Offline

correct me if I'm wrong..

I manage to get the footerrow data working.. but my problems is i can only view the total for the active grid.. meaning:

currently i hv six(6) pages of data.. and each page will only show the total for each page…

how can i show the GRAND total for the whole six page to be viewed as the total in every page??

which part of the code should i edit...

this is the constructing json data code..

$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    
    $amttot += $row[cur_amount];

    
    $responce->rows[$i]['id']=$row[int_claimdetailid];
    $responce->rows[$i]['cell']=array($row[int_claimdetailid],$row[txt_item],$row[int_claimid],$row[dt_date],$row[int_reference],$row[cur_amount],$row[int_siteid],$row[int_accid]);
    $i++;
}
$responce->userdata['cur_amount'] = $amttot;
$responce->userdata['int_reference'] = 'Totals:';

help please anyone…

newbie..

01/02/2010
10:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

In userdata you should put the total calculations and not per page. Change your server side script to do this

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

01/02/2010
10:51
Avatar
aznan
Member
Members
Forum Posts: 32
Member Since:
14/01/2010
sp_UserOfflineSmall Offline

can u point to which part of my code above need to be change tony (which part says that in should return by page)

or is it inside somewhere else.. which part of my php??

.. or can u show me some sample.. the problem also persist when i try "true scrolling row".. or am i doing it wrongly.. ??

sorry for asking too muchh..

01/02/2010
12:21
Avatar
aznan
Member
Members
Forum Posts: 32
Member Since:
14/01/2010
sp_UserOfflineSmall Offline

ahh.. figure out myself but dunno whether right or wrong... I created a new sql.. and copy the while operation.. and delete here and there... thanxxx...

01/02/2010
13:10
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

It is a simple - from where comes this

$responce->userdata['cur_amount'] = $amttot;
$responce->userdata['int_reference'] = 'Totals:';

Then try to recalculate $amttot for the entry column.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

29/06/2010
12:50
Avatar
aznan
Member
Members
Forum Posts: 32
Member Since:
14/01/2010
sp_UserOfflineSmall Offline

tony and anyone,

 i'm trying to use :

toolbar: [true,"bottom"]

var udata = $("#toolbar2").jqGrid('getUserData');

$("#t_toolbar2").css("text-align","right").html("Totals Amount:"+udata.tamount+" Tax: "+udata.ttax+" Total: "+udata.ttotal+ "&nbsp;&nbsp;&nbsp;");

but  I cant seem to get the userdata value from json data

for example   i wish to change tamount in the demo to cur_amount.. in my apps...

$responce->userdata['cur_amount'] = $amttot;  

& next question instead of using the toolbar menthod, can userDataOnFooter be style with css also..  cause i wanted it to stand out from other data... example would be nice..

tq

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
68 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information