简体   繁体   English

WPF DataGrid自定义分组

[英]WPF DataGrid custom grouping

I'm kinda new to WPF and need some advice on how to implement a custom grouping setup for the DataGrid. 我是WPF的新手,并且需要一些有关如何为DataGrid实现自定义分组设置的建议。 I know the normal wpf DataGrid can do grouping, but potentially transferring 500k records over a crappy third world network and then have the crappy, cheap, and 5+ year old pc crawl through the data is not an option. 我知道普通的wpf DataGrid可以进行分组,但是可能无法通过糟糕的第三世界网络传输50万条记录,然后让糟糕,便宜且有5年以上历史的PC抓取数据。 In africa companies would generally invest in semi decent server setups, but when it comes to the end user machines... sadly anything that can still power on will do. 在非洲,公司通常会在半成品服务器上进行投资,但是对于最终用户机器……可悲的是,任何仍然可以开机的机器都可以。 So I need to do all the work on the server to the point that the end user pc only has to do the bare minimum to render only what is needed on the screen. 因此,我需要在服务器上进行所有工作,以使最终用户PC只需要做最少的工作即可仅渲染屏幕上所需的内容。 This is the case for Winforms, wpf, and even HTML. Winforms,wpf甚至HTML就是这种情况。

First, we already have a web front end that is working well. 首先,我们已经有一个运行良好的Web前端。 It's kinda our proof of concept version. 这有点像我们的概念证明版本。 Currently I'm working on reworking most of the back end logic to run in a wcf service and then have web and wpf front ends connect to the same service. 当前,我正在重新设计大多数后端逻辑,以使其在wcf服务中运行,然后将web和wpf前端连接到同一服务。

I already do my grouping server side along with the sort order and then only pull the few records I need to send to the front end out of the result set. 我已经完成了分组服务器端的排序顺序,然后只从结果集中提取了需要发送到前端的几条记录。 I mark each row as either a Header, Data, or Footer and then on the client I just run from the top of the result set to the bottom and render each row appropriately. 我将每一行标记为Header,Data或Footer,然后在客户端上,我从结果集的顶部一直运行到底部,并适当地渲染每一行。 Below is an example of what we more or less want and the page count was set to 10. Note that it's just random junk data. 下面是我们或多或少想要的示例,并将页面数设置为10。请注意,这只是随机的垃圾数据。

例

What is important to note here is that only records that are part of an Open Group is sent to the client. 这里要注意的重要一点是,只有属于Open Group的记录才发送到客户端。 The 5 closed groups in the image don't have any child records on the client front end. 图像中的5个封闭组在客户端前端没有任何子记录。 Only when a group is Open will the result set coming from the server contain child records to be rendered on the screen. 仅当组为“打开”时,来自服务器的结果集才会包含要在屏幕上呈现的子记录。 If you count the group headers and detail rows you will see it adds up to 10. Group footers don't count to the page size limit. 如果您计算组页眉和详细信息行,您将看到总计为10。组页脚不计入页面大小限制。 So in total I only sent 20 (Footers are in the result set) rows of information from the server to the client and not the 1000 records with 61 columns that's actually in the table. 因此,总共我只从服务器向客户端发送了20行(结果集中有页脚)信息,而没有在表中实际发送有61列的1000条记录。

Doing it like this is waaaaayyyy faster than potentially sending 10 000 records to the user machine and then do the sorting, grouping, and paging on the user machine. 这样做的速度要比潜在地向用户计算机发送10000条记录然后在用户计算机上进行排序,分组和分页要快得多。

Could I use what I have, or something like it, in a wpf datagrid? 我可以在wpf数据网格中使用我拥有的或类似的东西吗? How do I get the datagrid to render 3 different types of rows as shown above? 我如何获得数据网格以呈现3种不同类型的行,如上所示? Or should I not look at the DataGrid and do something else to render the data? 还是不应该查看DataGrid并做其他事情来呈现数据?

Decided to just make my own "DataGrid" using the WPF Grid with column and Row definitions. 决定使用带有列和行定义的WPF网格来制作自己的“ DataGrid”。 The other option seems to be the WPF Table which seems to work kinda like the HTML table. 另一个选择似乎是WPF表,它的工作方式似乎类似于HTML表。

I now just have to implement my own Drag and Drop to change column order and to allow sorting on column header clicks. 现在,我只需要实现自己的拖放操作即可更改列顺序并允许对列标题单击进行排序。 Already figured out the Drag and Drop so progress is being made. 已经找到了拖放功能,因此正在取得进展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM