title: jqgrid calculate total column cells amount depending on other column cell values
body: <p>After using jqgrid's setFooterData function to calculate the total amount like in <a href="https://stackoverflow.com/questions/5121350/jqgrid-access-cell-data-while-it-is-being-edited">this question</a> , this is my grid and functions:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      function calculateTotal(grid_ , column_id_)
      {
          var _total_amount = 0;
          var i = getColumnIndexByName(grid_ , column_id_); 
  
          // TO ADD - calculate only if row "status" cell = "1:Confirmed"
          $("tbody &gt; tr.jqgrow &gt; td:nth-child("+(i+1)+")" , grid_[0]).each(function()
          {
              _total_amount += Number(getTextFromCell(this));
          });
  
          return _total_amount;
      }
  
      function getColumnIndexByName(grid_ , column_id_)
      {
          var cm = grid_.jqGrid('getGridParam','colModel');
          for (var i=0,l=cm.length; i&lt;l; i++)
          {
              if (cm[i].name===column_id_)
              {
                  return i; // return the index
              }
          }
          return -1;
      }
  
      function getTextFromCell(cellNode)
      {
          return cellNode.childNodes[0].nodeName === "INPUT"?
                    cellNode.childNodes[0].value:
                    cellNode.textContent || cellNode.innerText;
      }
  
      $(document).ready(function () {
  
          var grid = $("#list"),lastSel;
  
          grid.jqGrid({
              url:'url',
              datatype: "xml",
              loadonce:true ,
              async: false,
              colNames: ['Inv No', 'Name' , 'Amount' , 'Status'],
              colModel: [
                  { name: 'id', index: 'id', width: 65, sorttype: 'int', hidden: true },
                  { name: 'name', index: 'name', editable: true, width: 90, sortable: false },
                  { name: 'amount', index: 'amount', editable: true, width: 70, formatter: 'number', align: 'right', sortable: false },
                  {name:'status',index:'status', width:90, sorttype:"int" , editable:true,
                    edittype:"select", formatter:'select',
                    editoptions:
                    {
                       value:"1:Confirmed ;2:Open ; 3:Rejected" ,
                       dataInit: function(elem)
                       {
                          $(elem).width(90);
                       }
                    }
                  },
              ],
              rowNum: 1000,
              pager: '#pager',
              viewrecords: true,
              sortorder: "desc",                
              height: "100%",                
              footerrow:true,
              xmlReader: {
                                            root:"rows",
                                            row:"row",
                                            repeatitems:false
                                         },
              shrinkToFit: false,
              beforeSelectRow: function(row_id_, e)
              {
              },
              onSelectRow: function(id)
              {
                   grid.jqGrid('saveRow' , lastSel , false, 'clientArray');
                   grid.editRow(id , false);
                   lastSel=id;
              },
              loadComplete:function()
              {
                  grid.jqGrid('footerData' , 'set' , {name:'TOTAL:' , amount: calculateTotal(grid , 'amount')});
              }
          });            
      });    
  &lt;/script&gt;
  </code></pre>
  
  <p>My question Is how can I calculate the total amount sum depending on the value that is iniside the "status" combobox. I want to sum the amount only if the value iniside the "status" cell is equels to "Confirmed" (=1). </p>
  
  <p>How can this be done?</p>
  
  <p>Thank's.</p>