I have pasted this table here to show a loose example of what I'm trying to do. I'm new to Grouping/Summarizing with Infragistics and need some tips.
In the case above there are 2 rows for Comp1 in the accompanying DataTable. The ID and Col1 values are the same for both of these rows. Then they have different values for Col2 as can be seen.
There is a "Total" at the bottom of every row in this Grid that sums Col3 and Col4. Then a Grand Total at the bottom of the Grid that sums these columns for every row.
There could be any number of rows for every Company. There were just 2 in this example. There can even be only 1 but the total will still display.
Any ideas how I should approach this problem?
I've tried adding the Company column to SortedColumns but end up with headers above every row rather than just at the top and I want the Company cells to merge together like is seen with "Comp1" above.
Is what I'm looking for possible? Or something close at least?
Hi Caleb,
In order to get a summary for each company, you would need to group by that company and thus introduce another level in the hierarchy. There's no way to insert a summary into the middle of a rows collection like you have in your mockup here.
Having said that, I think it should be pretty simple to get very close to what you have here. I have attached a small sample project here with a quick attempt to get as close as possible to your mockup.
Actually, I made some decisions that don't exactly match the mockup, but which I thought were better. :)
For example, I put the summaries into the GroupByRow itself, in addition to having them at the bottom of each group. You could turn these off easily enough by removing the InGroupByRows flag from the SummaryDisplayArea property, if you like. In fact, you might want to play around with the various SummaryDisplayArea options, anyway, just to see which one(s) work best for your needs.
And here's the relevant code:
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { var layout = e.Layout; var band = layout.Bands[0]; var ov = layout.Override; // In order to provide a summary for each company, you need to group by the company. var companyColumn = band.Columns["Company"]; layout.ViewStyleBand = ViewStyleBand.OutlookGroupBy; band.SortedColumns.Add(companyColumn, false, true); // Add a summary for column 3. var column3 = band.Columns["Col3"]; band.Summaries.Add(SummaryType.Sum, column3); // Add a summary for column 4. var column4 = band.Columns["Col4"]; band.Summaries.Add(SummaryType.Sum, column4); ov.SummaryDisplayArea = SummaryDisplayAreas.InGroupByRows | // This will give us summaries in the GroupByRow itself SummaryDisplayAreas.BottomFixed | // This will give us a grand total at the bottom. SummaryDisplayAreas.GroupByRowsFooter // This will give us a summary under each GroupByRow ; // Make the summaries in the GroupByRow appears as cells instead of just raw text. ov.GroupBySummaryDisplayStyle = GroupBySummaryDisplayStyle.SummaryCells; }
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { var layout = e.Layout; var band = layout.Bands[0]; var ov = layout.Override;
// In order to provide a summary for each company, you need to group by the company. var companyColumn = band.Columns["Company"]; layout.ViewStyleBand = ViewStyleBand.OutlookGroupBy; band.SortedColumns.Add(companyColumn, false, true);
// Add a summary for column 3. var column3 = band.Columns["Col3"]; band.Summaries.Add(SummaryType.Sum, column3);
// Add a summary for column 4. var column4 = band.Columns["Col4"]; band.Summaries.Add(SummaryType.Sum, column4);
ov.SummaryDisplayArea = SummaryDisplayAreas.InGroupByRows | // This will give us summaries in the GroupByRow itself SummaryDisplayAreas.BottomFixed | // This will give us a grand total at the bottom. SummaryDisplayAreas.GroupByRowsFooter // This will give us a summary under each GroupByRow ;
// Make the summaries in the GroupByRow appears as cells instead of just raw text. ov.GroupBySummaryDisplayStyle = GroupBySummaryDisplayStyle.SummaryCells; }
InGroupByRows
This is helpful but I'm still having some issues.
Now I have something that looks like this:
I'd post a pic but I don't think I have access to any image sharing services and I cannot simply upload one it seems...
So a few problems here. This is extremely cluttered and hard to read.
Thee CC1C should be vertically centered^
I'll keeping playing with it for now to see what I can find...
Caleb Whitaker said:Can I have the column headers only appear at the top of the Grid rather than on every. single. group?
Yes.
ov.HeaderPlacement = HeaderPlacement.FixedOnTop;
Caleb Whitaker said:Rather than having a Summaries row and then another row directly below that with the actual sums can they be on the same row?
Not really. You could turn off the summary footer caption. And then you could add a summary with some plain text in it. But you'd have to align it to a column or to some fixed position (Left, Right, or Center). And then you would end up with a second row if two summaries overlapped - if the user moved the columns around, for example. One problem with this approach, though, is that the summary will not size to fit it's content, so the text will likely be clipped. It might be best to simply turn off the summary footer and leave it at that.
Caleb Whitaker said:Are there different types of grouping? Like instead of this expanded tab thing for every Company could there not just be a "Company" column where the cells were merged and said e.g. "CC1C" one time. And this space would be larger based on the number of records that ended up in that group.
No. You could achieve this sort of grouping by sorting by the ID column and then using Cell Merging to merge the duplicate ID columns into one big cell. But that's not really grouping and you would not be able to have summary rows for each group in that case.