Is there a way I can create a sub total for each group and a grand total for the whole grid?
Thanks
Is there a way I can create a sub total for each group and a grand total for the whole grid?
Thanks
You can add a subtotal for each group by overriding getGroupTitle() and inspecting the groupNode to get all the groupMembers, and doing a sum.
You can add a total for the whole grid by manipulating the groupTree which becomes listGrid.data when you are grouped - just add a node at the end.
groupTree in Listgrid
As mention in document If the ListGrid is grouped, return the underlying tree structure.
Do we have any example on groupTree in Listgrid.
In documentation, we have very short desciption.
My requirement is that I want to show with grouping i want to show total of all rows on the same row where grouped filed is displayed with + icon.
Treegrid gives the facility to show remaining column with group by field also.
Is it possible in Listgrid?
List grid subTotal
Please could you explain with an example, how i can get subtotals for groups, using groupNode and groupMember.
For example, for the below ListGrid , how can i add up the population of all countries belonging to a continent, after grouping the records by Continent .
<code>
isc.ListGrid.create({
ID: “countryList”,
width:500, height:224,
alternateRecordStyles:true, cellHeight:22,
dataSource: countryDS,
fields:[
{name:“countryName”},
{name:“continent”},
{
name:“population”,
formatCellValue:“isc.Format.toUSString(value);”,
groupBy:function(‘continent’){
// ???
}
getGroupTitle : function (groupValue, groupNode, field, fieldName, grid) {
// ???
}
},
{name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png"}
],
groupStartOpen:"all",
autoFetchData: true
});
</code>
Please help !! I have been struggling with this ..
hi..this is exactly something i have been stuggling with
just 1 simple example would make us all happy i think…i have almost the same situation, and all i want is to simply have the groupheader look like this:
GROUPED ITEM NAME sumofTotal (within this group)
-field field field Total
-field field field Total
-field field field Total
GROUPED ITEM NAME sumofTotal
-field field field Total
-field field field Total
-field field field Total
GROUPED ITEM NAME sumofTotal
-field field field Total
-field field field Total
-field field field Total
this is one simple thing my brains just can’t figure out using your otherwise very wonderful documentation..please help..
Totals in group header at last
//OBJECT START creditsDS
isc.RestDataSource.create({
ID:“creditsDS”,
showPrompt:false,
fields:[
{name:“ID”, title:“ID”, primaryKey:true},
{name:“user”, title:“User”,width:‘25%’},
{name:“sales_person”, title:“Name”,width:‘25%’, showIf:‘false’,
getGroupTitle: function(groupValue, groupNode, field, fieldName, grid){
var nodes = $A(groupNode.groupMembers);
var total = 0;
for (var i = 0; i < nodes.length; i++){
total += nodes[i].credit;
}
return groupValue + (total).toFixed(2);
}
},
{name:“time”, title:“Date”,type:“date”,width:‘25%’,displayFormat: ‘toSerializeableDate’},
{name:“credit”, title:“Amount”,type:“double”,width:‘25%’},
],
autoFetchData:true,
fetchDataURL: ‘admin/credits/fetch_data.php’,
updateDataURL:“admin/credits/update_record.php”,
removeDataURL:“admin/credits/delete_record.php”,
addDataURL :“admin/credits/add_record.php”
});
//-----------------------
//OBJECT START myGrid
isc.ListGrid.create({
ID:'myTreeGrid',
showResizeBar:true,
dataSource:creditsDS,
groupByField: "sales_person",
groupStartOpen:"none",
alternateRecordStyles:true,
emptyCellValue: "--",
top:'25%', left: "700",width:"410", height:"75%",
loadingDataMessage:'getting data',
dataPageSize: 50,
showFilterEditor:true,
autoFetchData:true,
canEdit: false,
modalEditing:true,
canDragRecordsOut: true,
dragDataAction: "copy",
canRemoveRecords :false,
animateRemoveRecord:true
});
// ---------------------------------
this works for me..but I’m also using prototype with smartclient..love m both..
so thats why i can do this $A..which makes an array out of any object etc..
notice the get group title..
getGroupTitle: function(groupValue, groupNode, field, fieldName, grid){
var nodes = $A(groupNode.groupMembers);
var total = 0;
for (var i = 0; i < nodes.length; i++){
total += nodes[i].credit;
}
return groupValue + (total).toFixed(2);
}
},
that could be done in many different ways..and I was hoping that there were some kind of easier way to totalize or use a formula and put it in the group header..or wherever else it may be necessary.
i love love SmartClient but this would be something nice, many users are requesting totals rows and things of the sort…instead of thinking in terms of totalsRow..i’d rather picture a row on which some kinds of function can be run like sum or avg etc..or even calculation like "sum(the column we need) + (0.10 * sum(the column we need))…
Anyway..great software, great support…and big names who rely on Smartclient..all the ingredients for success..thnx guys
The equivalent SmartClient code there would be groupNode.groupMembers.getProperty(“credit”).sum() - shorter and more readable.
thanx
that was exactly what i have been looking for for about a week now..a nice and simple way from withing smartclient without relying on third party code