ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Group Total / grand total in grid
Title:
B
I
{code}
?
As per demo grid total or count showing page wise ... Not group wise or sub group wise. Every page it is giving page wise count / total in footer ... How to get that group total / grand total
Save Changes
Cancel
SK
asked at 04 Jun 2020
Answers
B
I
{code}
?
In this demo: https://demo.aspnetawesome.com/GridDemo/Grouping you can see the totals being calculated in the `MakeFooter` function, the calculations in the demo are being made using `info.Items` which contains the items for the current group in the current page, you could ignore `info.Items` and calculate the Total directly from the unpaged data source. `info.Column` contains the name of the current Group `gp.Groups` will contain all the groups in order, so using this info you could query your data source and calculate the unpaged group total. you could use Dynamic Linq for that https://dynamic-linq.net MakeHeader = GetMakeHeader(g), ... private Func<GroupInfo<Lunch>, GroupHeader> GetMakeHeader(GridParams gp) { // getting the aggregate values irrespective of how many items we are rendering in the current page GroupHeader Func(GroupInfo<Lunch> info) { // get first item in the group var first = info.Items.First(); // get the grouped column value(s) for the first item var val = string.Join(" ", AweUtil.GetColumnValue(info.Column, first).Select(ToStr)); var query = Db.Lunches.AsQueryable(); foreach (var groupName in gp.Groups) { var names = groupName.Split(','); // for grouping by Chef column Chef.FirstName,Chef.LastName for (var i = 0; i < names.Length; i++) { var name = names[i]; var gvals = AweUtil.GetColumnValue(groupName, first).ToArray(); query = query.Where(name + "==@0", gvals[i]); // using Dynamic Linq } if (groupName == info.Column) break; } return new GroupHeader { Content = string.Format(" {0} : {1} ( Count = {2} )", info.Header, val, query.Count()) }; } return Func; }
Save Changes
Cancel
Omu
answered at 04 Jun 2020
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK