英文:
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<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;
}
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论