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);
Hello mhead1 ,
Thank you for posting in our forum.
For the summary feature the summaries will only get calculated once the changes made on the grid have been committed.
If autoCommit is set to true that will happen the moment you end the editing of the cell. You could also manually commit the changes using the commit method:
$(".selector").igGrid("commit");
If you have a remote data source set with an updateUrl then when you commit the grid will attempt to send the transactions to that url.
If the data source is local it will reflect the changes in that data source.
In both cases after that the pending transactions in ig_transactions will be cleared.
Depending on your scenario you could specify an update url and commit the changes in the grid in its data source separately.
If your business logic does not allow you to commit the grid’s changes then you won’t be able to use the summary feature. In that case you’d have to use your custom approach to calculate the sum manually.
Let me know if you have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer II
Infragistics, Inc.
http://ko.infragistics.com/support
Thank you for your quick reply.
I have to send the data at one time unfortunately.
The workaround works well for what I need it for.
It would be nice if the Summaries feature would take pending transactions into account though.
Thank you,
Michael