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_Related Related Topics sp_TopicIcon
Summing a Column with local data
20/07/2010
18:53
Avatar
donsom0702
Member
Members
Forum Posts: 5
Member Since:
08/07/2010
sp_UserOfflineSmall Offline

I am a newbie with jqgrid and trying to do some prototyping with local data.   I want to be able to sum columns to display a total on another area of the page.   I have the sum working when the grid first loads and if I add a row using the afterInsertRow event.   However I am not sure how to do the delete and udpate.   I have tried the AfterComplete and AfterSubmit events to no avail.   My code is below.   Any help would be appreciated. 

Don

$(document).ready(function(){
  var lastSel = "";

  jQuery("#grid").jqGrid({
    datatype: 'local',
    mtype: 'GET',
    colNames:['Student ID',
              'Student Name',
              'Proj Awards',
              'Prev Awards',
              'Award Amt',
              'Total',
              'R',
              'GPA',
              'County',
              'Comm Serv',
              'OSU Orgs'],
    colModel :[
      {name:'ID', index:'ID', width:100, editable: true },
      {name:'NAME', index:'NAME', width:130, editable: true},
      {name:'PROJ', index:'PROJ', width:80, editable: true, formatter:'currency'},
      {name:'PREV', index:'PREV', width:80, editable: true, formatter:'currency'},
      {name:'AWARD', index:'AWARD', width:80, editable: true, formatter:'currency'},
      {name:'TOTAL', index:'TOTAL', width:80, editable: true, formatter:'currency'},
      {name:'R', index:'R', width:15, editable: true},
      {name:'GPA', index:'GPA', width:50, editable: true},
      {name:'COUNTY', index:'COUNTY', width:50, editable: true},
      {name:'COMSERV', index:'COMSERV', width:200, editable: true},
      {name:'OSUORG', index:'OSUORG', width:200, editable: true}
    ],
    rowNum:10,
    rownumbers: true,     // add row numbers to display
    rowList:[10,20,30,40,50,100],
    pager: '#pager',
//    scroll: 1,
//    scroll: true,
    sortname: 'ID',
    sortorder: 'asc',
    //shrinkToFit: false,
    autowidth: false,
    height: 300,
    width: 1000,
    altRows: true,
    viewrecords: true,
    onSelectRow: function(id){
         if(id && id !== lastSel){
            if (lastSel != "")
            {  
               jQuery('#grid').restoreRow(lastSel);   
            }    
            lastSel=id;
         }
         jQuery('#grid').editRow(id, true);
    },
    afterInsertRow: function(id, data, elem){
        var tot = jQuery("#grid").getCol('AWARD',false);
         var sumawd=0;
         for(var i = 0; i < tot.length; i++ ){
            if (tot[i] != "")
            {  
               sumawd = sumawd + parseFloat(tot[i]);  
            }  
         }
         $('#totcurr').text('$' + sumawd);    
       },  
   errorCell: function(resp, status) {
      alert('post submit');
   },
   editurl: 'dummy_ajax.php',   
   caption: 'Student Scholarships'
  });

  jQuery("#grid").jqGrid('navGrid','#pager',{search:true,
                                             add:true,
                                             del:true,   
                                             edit:false,
                                             refresh:false}
                                             );

   // create test data
   var ids = new Array("111-111-111","222-222-222","333-333-333","444-444-444","555-555-555","666-666-666","777-777-777","888-888-888","999-999-999");
   var names = ["Ames, Martha","Rogers, Alan","Trandt, Janice","Wilson, Mark","James, David","Smith, Elise","Walker, Jackie","Fall, Terrance","Russel, Carl"];
   var proj  = ["4000","4000","3500","3500","3500","3000","","3000","2000"];
   var prev  = ["3500","2000","2000"," ","1000","2000","","","2000"];
   var award  = ["250","1000","","1000","500","500","","",""];
   var total  = ["3750","3000","2000","1000","1500","2500","","3000","2000"];
   var gpa  = ["4.00","4.00","3.85","3.87","3.85","3.61","3.88","3.58","3.50"];
   var county  = ["Lane","Benton","Benton","Benton","Lane","Benton","Lane","Lane","Benton"];
   var comserv  = ["Habitat for Humanity","Samuels Men's Shelte","Linn Benton Food Share","4H Counselor","Boy Scout Leader","","Walk for Life Organizer","",""];
   var osuorg  = ["Pres. Student Govt","OSU Band","OSU Animal Shelter","OSU Mentoring Program","","OSU Safe Ride","OSU Mentoring Program","",""];
   var cnt=1;
   for(var i = 0; i < 8; i++ ){
      cnt = i + 1;    
      var bob = {ID:ids[i],
         NAME:names[i],
         PROJ:proj[i],
         PREV:prev[i],  
         AWARD:award[i],
         TOTAL:total[i],
         R:"",
         GPA:gpa[i],
         COUNTY:county[i],
         COMSERV:comserv[i],
         OSUORG:osuorg[i]
      };

      $('#grid').jqGrid().addRowData(cnt,bob,'last');
   }  
   
   
});
    
 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
66 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