如何在运行时向GridView中添加计算列

huangapple go评论78阅读模式
英文:

How to add calculated Columns to GridView at Runtime

问题

以下是翻译好的部分:

  1. 我有三个 DACsPeople(PeopleID, Name),Skills(SkillID, Name) SkillValues(PeopleID, SkillID, Value)。当我向 Skills 添加记录时,它应该显示为一个列在我的图表上的 Grid 中,该 Grid 显示了人员列表。这是我现在的代码,但它不会添加任何列到 Grid 中。然而,当我打开页面时它是可以运行的,所以我对它的可能性持乐观态度。
  2. public class MyGraph: PXGraph<MyGraph>
  3. {
  4. public MyGraph()
  5. {
  6. AddSkillColumns(MasterView.Cache);
  7. }
  8. private void AddSkillColumns(PXCache sender)
  9. {
  10. PXResultset<Skills> rows = SelectFrom<Skills>.View.Select(this);
  11. foreach (Skills row in rows)
  12. {
  13. String key = String.Format("Comp_{0}",row.SkillID.ToString());
  14. if(!sender.Fields.Contains(key))
  15. {
  16. sender.Fields.Add(key);
  17. this.FieldSelecting.AddHandler("MasterView", key, (PXCache cache, PXFieldSelectingEventArgs args) =>
  18. {
  19. });
  20. this.FieldUpdating.AddHandler("MasterView", key, (PXCache cache, PXFieldUpdatingEventArgs args) =>
  21. {
  22. });
  23. }
  24. }
  25. }
  26. public SelectFrom<People>.View.ReadOnly MasterView;
  27. }

请注意,翻译中的代码部分没有被翻译,仍然是原文的英文代码。

英文:

I have three DACs, People(PeopleID, Name), Skills(SkillID, Name) and SkillValues(PeopleID, SkillID, Value). When I add a record to Skills, it should be shown as a column in a Grid on my Graph that shows the list of People. This is the Code I have right now, but it doesn't add any columns to the Grid. However, it runs when I open the page, so I'm optimistic that it is possible somehow.

  1. public class MyGraph: PXGraph&lt;MyGraph&gt;
  2. {
  3. public MyGraph()
  4. {
  5. AddSkillColumns(MasterView.Cache);
  6. }
  7. private void AddSkillColumns(PXCache sender)
  8. {
  9. PXResultset&lt;Skills&gt; rows = SelectFrom&lt;Skills&gt;.View.Select(this);
  10. foreach (Skills row in rows)
  11. {
  12. String key = String.Format(&quot;Comp_{0}&quot;,row.SkillID.ToString());
  13. if(!sender.Fields.Contains(key))
  14. {
  15. sender.Fields.Add(key);
  16. this.FieldSelecting.AddHandler(&quot;MasterView&quot;, key, (PXCache cache, PXFieldSelectingEventArgs args) =&gt;
  17. {
  18. });
  19. this.FieldUpdating.AddHandler(&quot;MasterView&quot;, key, (PXCache cache, PXFieldUpdatingEventArgs args) =&gt;
  20. {
  21. });
  22. }
  23. }
  24. }
  25. public SelectFrom&lt;People&gt;.View.ReadOnly MasterView;

}

答案1

得分: 1

你需要在自定义编辑器中将列添加到网格中,并在需要时在RowSelected事件中显示/隐藏它们。

更新:

如果你真的想在运行时添加列,你可以在你屏幕的aspx.cs文件中执行。在GL302010.aspx.cs中有一个很好的示例。

英文:

You need to add your columns to the grid in the customization editor, and show / hide them in a RowSelected event if necessary.

Update:

If you really want to add your columns runtime, you can do it in the aspx.cs file of your screen. There is a good example in GL302010.aspx.cs

huangapple
  • 本文由 发表于 2023年8月10日 21:30:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876204.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定