Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1015
How to get sum of column with autoCommit false
posted

Can someone please tell me the best way to calculate the sum of a column of values when the grid has:

autoCommit: false

aggregrateTransactions: true

My scenario is that I have a "Services" grid with a service, quantity, price, extended price.

Users can add, edit, and delete with the grid.  There is no filtering, sorting , or paging.  The sum of the extended price must be kept in a field outside of the grid on a form (like an invoice).  There is actually another grid for parts.  When the user submits the invoice, I send the ig_transactions along with the form for processing. There are setting for the grid to calculate the extended price based on quantity and unit price. 

I have added the feature "Summaries" but it only will work when the autoCommit is set to true.  It will not sum the rows that are edited or added when autoCommit is false. 

I am using the following for now unless there is a better way.  Please advise.

In the grid rowDeleting event:

//set all values to zero

rowDeleting:function (evt, ui) { $gridJobService.igGridUpdating("updateRow", ui.rowID, { Quantity: 0, UnitPrice: 0, ExtPrice: 0 });

  }

 

In the grid rowDeleted and editRowEnded events:

var ExtPrice = 0, id = "", value = 0;

$gridJobService.igGrid("allRows").each(function (index) {

 id = $(this).attr("data-id");

try{

 value = $gridJobService.igGrid("getCellValue", id, "ExtPrice");

}

catch(err) {

value = 0.00;

}

ExtPrice += parseFloat(value);

});

//update the field on the form

$("#TotalServiceAmount").igNumericEditor("value", ExtPrice);

 

Parents Reply Children
No Data