Hi team
I need to render a XamDataGrid in my WPF application where certain columns are dynamic in nature. the number of such columns may vary depending on the data in the database.
Such columns should have a common group heading. Please refer to below columns in the excel
The number of rows are also not know before hand.
Also certain rows are disabled on possibly a hidden column value. The rows in dark.
Certain cells should be shaded out as necessary
We use MVVM in our project and avoid using code behind wherever possible.
Negative numbers are displayed in red with brackets indicating that there is formatting to be applied
Below is the exact of the grid required.
Request you to please suggest how the below requirement can be achieved.
Hello Manesh,
There are a few ways that I could see that you could achieve your requirement with the XamDataGrid, and in these ways, one thing that would remain consistent is the "field grouping" functionality that you are looking for regarding your "month" fields that you have listed. To achieve this part, you could utilize the Field Grouping feature that was added in the 16.1 version of the WPF product. You can read about Field Grouping in our online documentation, here: http://www.infragistics.com/help/wpf/xamdatagrid-field-grouping.
The negative number formatting could be achieved using a Style for CellValuePresenter and a converter. I would recommend that you see the following blog post regarding CellValuePresenter conditional formatting: http://www.infragistics.com/community/blogs/alex_fidanov/archive/2010/01/12/howto-using-wpf-converters-to-style-the-xamdatagrid.aspx.
The other parts that you are looking to achieve would really depend on how exactly you want your page layout to look and behave. From the way that you have presented your data, I see a couple of different options that you could go with. For one, you could create a single grid with all of the data that you have listed inline, but this would be the most complex, and most difficult way, as it would require quite a bit of styling and inclusions of identifiers for which rows are "header" rows (i.e. "Fixed Assets, Cash Distribution, etc.) and whether or not rows are distribution amounts or assets, which would mainly be for the "N" and "Y" formatting that you wish to have applied. Another challenge that you may face by placing this entirely in a single grid inline would be getting your summaries in place, as you would likely have to calculate this manually if you used a single inline grid.
Instead of using a single inline grid, I would recommend that you do one of two things. The first is to group the header rows. In other words, you would have a separate column that contains what the header should be, and you could group by this column. This would allow you to use the built-in summary functionality for the XamDataGrid to calculate the summary "bands" for each of the groups. It would also create a sort of hierarchical view for you, which you could also use as a structure for your data, but I believe this would be more complex than the grouping option.
Another thing you could do is use multiple grids. This would make the "N" and "Y" formatting easier, as you would be able to write styles local to each grid, and then perhaps you could have a separate label that returns the "Total" for that particular grid or category. Using multiple grids, you could also do the grouping mentioned above.
If you would like, I can create you a sample project demonstrating some of these ways, but if you could please provide some information on the layout that you are looking for in your application, this would give me a good starting point so that I may create a sample project and provide you more information on exactly what you could do to achieve this dynamic scenario.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
Can you help me with a working sample to understand each approach.
The layout is the same as my previous post. However, below screenshot explains the layout details.
Please make strict use of MVVM with limited code behind as that is the standard we follow in our project.
While I am unable to see the screenshot that you had attached, I have created a full-MVVM project that demonstrates the three separate XamDataGrid layouts that I had listed in my original response to this forum thread. This sample project is attached.
As you can see from the sample project, the single, inline grid is the most complex, as most of the conditional formatting and styling is done based on triggers that designate whether or not something is an asset, distribution, header, or summary. The summaries are also entirely calculated manually. To leave this sample project somewhat simple, it does not currently re-calculate the manually calculated summaries if a value is changed. This would require you to listen to the DataTable for a value-change, and then do the recalculations that occur in the ViewModel at the moment.
The least complex of these three layouts is the inline, grouped grid. This grid uses some triggers for its editors in order to do the conditional formatting for the "M" and "Y" records that you have attached in your original post, but the summaries are calculated and displayed in the GroupByRecordPresenters. Since this grid is grouped in a multi-hierarchical way, you can get the summaries for each child band, which you cannot currently do without creation of a custom calculator otherwise.
The multiple-grid scenario is somewhat of a mixed bag when it comes to summaries. In one of the grids, the summaries needed to be manually calculated, as you have multiple "summary" rows that take different parts of the grid into account, but in the other, it uses the default built-in summary functionality in order to calculate a sum of the corresponding fields.
Also demonstrated in the sample project is the red negative numbers, and the field grouping functionality for your "month" fields.
Again, this sample project is attached. I hope it helps you.
Thanks for the sample.
However, I am using version 11.1 of infragistics and I get the below build errors. Is "FieldGroup" not supported in 11.1?
InfragisticsWPF4.DataPresenter.v11.1
InfragisticsWPF4.Editors.v11.1
InfragisticsWPF4.v11.1
Build errors
Error 23 The name "FieldGroup" does not exist in the namespace "http://infragistics.com/DataPresenter".
Error 24 The member "CellValuePresenterStyle" is not recognized or is not accessible.
Any updates on this ?
I have a demo scheduled tomorrow. Hence, request you to please consider this urgent.
Any update on this ?
All the three examples provided uses FieldGroup which is not supported in v11.1
Please confirm with a working sample if this is achievable using version InfragisticsWPF4 v11.1