ACCESS SUBGRID TO COUNT THE COLUMN AND SUM
SCENARIO:- Required total of field(priceperunit) in subgrid through javascript
Solution-I had executed below script.
//Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
function CostOfTotal()
{
debugger;
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("salesorderdetailsGrid") != null && Xrm.Page.getControl("salesorderdetailsGrid") != undefined) {
//if subgrid is not null then counts the grid total
var count = Xrm.Page.getControl("salesorderdetailsGrid").getGrid().getTotalRecordCount();
alert("Total Products:"+count);
for(i = 0; i < count; i++) {
//to get control on grid count, which coloum you need to fetch data(like i used priceperunit)
var gridControl = Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
alert(gridControl );
var cellValue = gridControl;
alert(cellValue);
cellValue = cellValue.replace( /,/,"." );
alert(cellValue);
var sum = sum + parseFloat(cellValue);
alert(sum);
}
}
//to set value in field.
Xrm.Page.getAttribute('new_total').setValue(sum);
}
SCENARIO:- Required total of field(priceperunit) in subgrid through javascript
Solution-I had executed below script.
//Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
I counted the grid total and based on count i fetched the data of 'priceperunit' data and total all the records present in sub grid.
{
debugger;
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("salesorderdetailsGrid") != null && Xrm.Page.getControl("salesorderdetailsGrid") != undefined) {
//if subgrid is not null then counts the grid total
var count = Xrm.Page.getControl("salesorderdetailsGrid").getGrid().getTotalRecordCount();
alert("Total Products:"+count);
for(i = 0; i < count; i++) {
//to get control on grid count, which coloum you need to fetch data(like i used priceperunit)
var gridControl = Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
alert(gridControl );
var cellValue = gridControl;
alert(cellValue);
cellValue = cellValue.replace( /,/,"." );
alert(cellValue);
var sum = sum + parseFloat(cellValue);
alert(sum);
}
}
//to set value in field.
Xrm.Page.getAttribute('new_total').setValue(sum);
}
No comments:
Post a Comment