使用什么逻辑对 PowerBuilder DataWindow 中已排序列中包含重复项的已排序行进行排序?
众所周知,PowerBuilder 中的数据窗口可以设计为根据列值对行进行排序。如果该列中的值是唯一的,则此方法可以正常工作。然而;我正在处理这些列并不总是唯一的情况,因此,当将 Sort() 函数应用于 DataWindow 时,重复项将相对于其他行进行排序,但本身不会以任何方式排序。
更好的表达方式是通过图表。
想象一下以下数据窗口:
应用一次排序
ID 描述 活动
1 ABC 1
2 BCD 0
3 BCD 1
4 CDE 1
排序应用两次
ID 描述 活动
1 ABC 1
3 BCD 1
2 BCD 0
4 CDE 1
排序应用三次
ID 描述 活动
1 ABC 1
2 BCD 0
3 BCD 1
4 CDE 1
如果我对 DESCR 列应用升序排序,则两个 BCD 行将交换位置。请记住,我仅在 DESCR 列上应用排序。排序功能似乎随机地将位置分配给重复的值。在我的示例中,如果我不断地将排序函数应用于该数据窗口,并在 DESCR 上进行升序排序,则 BCD 行将来回切换位置。
对于我的问题,有谁知道为什么会这样?我知道如何通过对隐藏列应用二次排序来解决这个问题,该隐藏列对重复值的集合进行编号。在我的例子中,ID 1 将被分配为 1。ID 2 将被分配为 1,ID 3 将被分配为 2。这样,BCD 值可以在 DESCR 上排序,然后在该隐藏列上排序。
然而;仅仅保持行的顺序相同会带来更多麻烦。只需在 Stack 上对 PowerBuilder 开发人员社区进行民意调查,看看他们是否遇到过此问题以及是否已修复该问题,或者确定 PB 只是随机分配顺序给排序行中的重复值。
As is known, the data windows in PowerBuilder can be fashioned to sort the rows based on a columns value. This works fine if the values in that column are unique. However; I am working on a situation where those columns are not always unique and as a result, when the Sort() function is applied to the DataWindow, the duplicates are ordered in respect to the other rows but are not ordered in anyway themselves.
A better way to say this would be through a diagram.
Imagine the following data window:
Sort applied once
ID DESCR ACTIVE
1 ABC 1
2 BCD 0
3 BCD 1
4 CDE 1
Sort applied twice
ID DESCR ACTIVE
1 ABC 1
3 BCD 1
2 BCD 0
4 CDE 1
Sort applied thrice
ID DESCR ACTIVE
1 ABC 1
2 BCD 0
3 BCD 1
4 CDE 1
If I apply a ascending sort to the DESCR column, the two BCD rows will switch places. I am only applying the the sort on the DESCR column remember. It seems like the sort functionality randomly assigns a position to values that are duplicated. In my example, if I continually apply the sort function to that data window with an ascending sort on DESCR, the BCD rows will switch back and forth places.
For the question I have, does anyone know why it works this way? I have an idea of how to maybe solve it by applying a secondary sort to a hidden column that numbers sets of duplicate values. In my case, ID 1 would be assigned a 1. ID 2 would get a 1 and ID 3 would get a two. This way, the BCD values could be sorted on the DESCR, and then on this hidden column.
However; that is a lot more hassle to just keep the rows in the same order. Just polling the PowerBuilder developer community here on Stack to see if they've encountered this and if they've fixed it or know for sure that PB just randomly assigns an order to duplicate values in a sorted row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将 ACTIVE 列添加到排序条件(即使您并不真正需要对其进行排序 - 这不会造成损害!),问题就解决了!
Simply add the column ACTIVE to the sort criteria (even if you don't really need it to be sorted - it will not harm!), and the problem is solved!