允许用户定义表顺序的最佳方式?

发布于 2024-07-13 20:50:23 字数 811 浏览 3 评论 0原文

允许用户定义表顺序的最佳方法?

我们使用 SQL Server 2005 和 DevExpress 控件。

我们有一个包含以下内容的表:

  1. 流程 A
  2. 流程 B
  3. 流程 C
  4. 报告 A
  5. 报告 B
  6. 报告 C

我们希望允许用户将顺序更改为他们想要的任何顺序。

下面是一个示例:

  1. 进程 C
  2. 进程 A
  3. 进程 B
  4. 报告 B
  5. 报告 A
  6. 报告 C

为了适应这一点,我们向应用程序维护的表中添加了一个 DisplayOrder (INT) 字段。

使用 INT 字段是用户定义订单的最佳解决方案吗?

还有其他方法可以实现此目的吗?

我要问的原因是,在我们当前的应用程序中,向下(或向上)移动一行大约需要 1 秒。 我即将破解代码,看看为什么要花这么长时间,如果 Stack Overflow 专家有任何好的想法,我可能会在那时实现它们。

如果您好奇,我相信我们的应用程序允许编辑 DisplayOrder 的方式如下:

  1. 将表加载到 GridView
  2. 选择一行
  3. 单击“下移”按钮(还有一个“上移”按钮)
  4. 单击事件将交换当前的 DisplayOrder行及其下方的行。
  5. 对两条记录的更改都会写回数据库
  6. 每次单击大约需要 1 秒(即 10 次单击等于 10 秒)

Best way to allow the User to define a Table’s Order?

We are using SQL Server 2005 and DevExpress controls.

We have a table that contains the following:

  1. Process A
  2. Process B
  3. Process C
  4. Report A
  5. Report B
  6. Report C

We want to allow the user to change the order to anything they want.

Here is one example:

  1. Process C
  2. Process A
  3. Process B
  4. Report B
  5. Report A
  6. Report C

To accommodate this we added a DisplayOrder (INT) field to the table that is maintainted by the our application.

Is using an INT field the best solution for a user defined order?

Are there any other methods to accomplish this?

The reason, I am asking, is in our current application it takes about 1 second to move a row down (or up). I am about to crack open the code to see why it is taking so long and if you Stack Overflow gurus have any good ideas, I might implement them at that time.

If you are curious, here is how I believe our application allows editing of the DisplayOrder:

  1. Load the table into a GridView
  2. Select a row
  3. Clicking a Move Down button (there is also a Move Up button)
  4. The Click Event will swap DisplayOrder of the current row with the row underneath it.
  5. The change, to both of the records, are written back to the database
  6. This takes about 1 second per click (i.e. 10 clicks equal 10 seconds)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

远昼 2024-07-20 20:50:23

每次交换是否会花费 1 秒,因为每次点击都会更新数据库? 也许甚至还要重新选择数据?

为什么不将数据选择到本地对象中。 绑定到网格中的那些对象。 当您上下移动对象时,可以调整它们的显示顺序属性。 对数据库进行更新

  1. 然后仅在用户最终单击“保存”时
  2. 。 如果对象的任何值已更改。

Could it be taking 1 second per exchange because you are updating the DB with each click? Maybe even reselecting the data again too?

Why not select the data into local objects. Bind to those objects in the grid. When you move the objects up and down adjust their display order property. Then only do an update to the DB

  1. When the user finally clicks Save.
  2. If any of the values of the object have changed.
ぶ宁プ宁ぶ 2024-07-20 20:50:23

我会将保存决策移至明确的“保存”按钮中以进行重新排序,因为用户可能会改变主意,并且正如 Peter Morris 所建议的那样,这将解决您的性能问题。

需要考虑的其他事项 - 明确的“移至顶部”和“移至底部”项目。

我使用这种方法在企业系统中实现了一个非常成功的 UI,用于用户驱动的可搜索项目和报告项目的选择。 有关 UI 的更多详细信息,可供您查看(请记住它大约有 15 岁了 - 回到平坦的单声道时代!)。 大量用户测试的一个关键改进是保存此订单的最佳位置不是每个用户或每个公司,而是每个组。 小组是一起工作的人,他们具有相同的起始页面(本质上是大规模连接图中的相同根)。 我们的组织中有大约 7 个独特的小组。

因此,如果您采用按用户或按组的方法,则需要将排序数据提取到一个单独的表中,该表将数据键映射到序数整数。

I would move the saving decision into an explicit Save button for the re-ordering because the user may change their mind and, as Peter Morris suggests, that will get past your performance problem.

Further things to consider - explicit Move to Top and Move to Bottom items.

I implemented a very successful UI using this kind of approach for user-driven selection of searchable items and reporting items, in an enterprise system. More details of the UI are available for you to see (be kind, remember it's about 15 years old - back in flat mono days!). One key refinement from a lot of user testing - the sweet spot for saving this order was not per-user or per-company but per-group. Groups were people working together who had a the same starting page (essentially the same root in a massively connected graph). We had about 7 unique groups in the organisation.

So, if you go for a per-user or per-group approach, you need to pull the sort data out into a separate table which maps data keys to ordinal integers.

新一帅帅 2024-07-20 20:50:23

如果您讨论的是用户想要设置和保留的显示顺序,则需要将其放在一个单独的表中,其中包含用户 ID 和他或她想要查看的记录的 ID 以及显示顺序列。 然后,将数据获取到该页面的查询将使用到用户首选项表的联接。

如果您只想暂时设置用户查看屏幕的时间顺序,请通过用户界面进行操作。

无论如何,不​​要对基表中的记录重新排序,这是一个糟糕的选择,因为您将遇到竞争条件,其中用户 a 想要一个设置,而用户 b 同时尝试更改为不同的设置。

If you area talking about a display order that the user wants to set and keep, that needs to be in a separate table with the userID and the ids of the records he or she wants to see and a display order column. Then the query that gets the data to that page would usea join to the user preference table.

If you want to just set the order temporaily for the time the person is looking at the screen, do it thorugh the user interface.

In any event do not reorder the records in the base table, that is a poor choice as you will run into race conditions where user a wants one setting and user b inthe meantime is trying to change to a differnt setting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文