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

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

How to add calculated Columns to GridView at Runtime

问题

以下是翻译好的部分:

我有三个 DACs,People(PeopleID, Name),Skills(SkillID, Name) 和 SkillValues(PeopleID, SkillID, Value)。当我向 Skills 添加记录时,它应该显示为一个列在我的图表上的 Grid 中,该 Grid 显示了人员列表。这是我现在的代码,但它不会添加任何列到 Grid 中。然而,当我打开页面时它是可以运行的,所以我对它的可能性持乐观态度。

public class MyGraph: PXGraph<MyGraph>
{
    public MyGraph()
    {
        AddSkillColumns(MasterView.Cache);
    }

    private void AddSkillColumns(PXCache sender)
    {
        PXResultset<Skills> rows = SelectFrom<Skills>.View.Select(this);
        foreach (Skills row in rows)
        {
            String key = String.Format("Comp_{0}",row.SkillID.ToString());
            if(!sender.Fields.Contains(key))
            {
                sender.Fields.Add(key);
                this.FieldSelecting.AddHandler("MasterView", key, (PXCache cache, PXFieldSelectingEventArgs args) =>
                {

                });
                this.FieldUpdating.AddHandler("MasterView", key, (PXCache cache, PXFieldUpdatingEventArgs args) =>
                {

                });
            }
        }
    }

    public SelectFrom<People>.View.ReadOnly MasterView;
}

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

英文:

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.

 public class MyGraph: PXGraph&lt;MyGraph&gt;
 {
    public MyGraph()
    {
        AddSkillColumns(MasterView.Cache);
    }

    private void AddSkillColumns(PXCache sender)
    {
        PXResultset&lt;Skills&gt; rows = SelectFrom&lt;Skills&gt;.View.Select(this);
        foreach (Skills row in rows)
        {
            String key = String.Format(&quot;Comp_{0}&quot;,row.SkillID.ToString());
            if(!sender.Fields.Contains(key))
            {
                sender.Fields.Add(key);
                this.FieldSelecting.AddHandler(&quot;MasterView&quot;, key, (PXCache cache, PXFieldSelectingEventArgs args) =&gt;
                {

                });
                this.FieldUpdating.AddHandler(&quot;MasterView&quot;, key, (PXCache cache, PXFieldUpdatingEventArgs args) =&gt;
                {

                });
            }
        }
    }

    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:

确定