编辑后如何在 GridPanel 中显示一对多相关列?

发布于 2025-01-08 17:58:37 字数 8245 浏览 0 评论 0原文

情况概述

我正在使用 Ext.NET GridPanel 来显示项目列表,其中包含分配给某些用户的任务(我称之为 Sprint)和状态。所以我得到了这种关系:

在此处输入图像描述

SprintOwner -> UserID
SprintStatus -> SprintStatusID

在我的 GridPanel 中,我显示按项目分组的冲刺,并使用关系以显示其名称而不是 ID(SprintStatusName 和 UserName)。它是葡萄牙语的,但我发现显示它很有用:

在此处输入图像描述

按此顺序我有名称、状态和 SprintOwner我可以编辑所有内容。

问题

在 Status 和 SprintOwner 中,我有一个组合框,其值与 ID 关联。编辑它后,网格会更新我的数据库并再次渲染数据,但它不会显示名称,而是显示值(ID),如下所示:

在此处输入图像描述

我怎样才能让它再次显示他们的名字?

因此我的 Page_Load 方法

Dim db As New ProjectManagerDataContext

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        ' Retorna as sprints do banco de dados
        ProjectsStore.DataSource = From sp In db.Sprints _
                            Select New With { _
                                .ID = sp.SprintID, _
                                .Name = sp.SprintName, _
                                .ProjectName = "[" & sp.Project.ProjectGroup1.ProjectGroupName & "] " & sp.Project.ProjectName, _
                                .Status = sp.SprintStatus1.SprintStatusName, _
                                .Owner = sp.User.UserName, _
                                .BeginDate = sp.SprintBegin, _
                                .EndDate = sp.SprintEnd, _
                                .RealEnd = sp.SprintRealEnd}
        ProjectsStore.DataBind()

        Store2.DataSource = From ss In db.SprintStatus _
                            Select New With { _
                                .StatusID = ss.SprintStatusID, _
                                .StatusName = ss.SprintStatusName}
        Store2.DataBind()

        Store3.DataSource = (From u In db.Users _
                             Select New With { _
                                .DeveloperName = u.UserName, _
                                .DeveloperID = u.UserID})
        Store3.DataBind()


    End If

End Sub

[已编辑]

和我的 .asp:

<ext:GridPanel 
        ID="grdProjects"
        runat="server"
        AutoHeight="true" 
        EnableColumnMove="false" 
        Collapsible="false"
        AnimCollapse="true"
        StripeRows="true" 
        Title="Projetos" >

        <Store>
            <ext:Store ID="ProjectsStore" runat="server" GroupField="ProjectName">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ProjectName" Type="String" />
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" Type="String" />
                            <ext:RecordField Name="Status" Type="String" />
                            <ext:RecordField Name="Owner" Type="String" />
                            <ext:RecordField Name="Begin" Type="Date" />
                            <ext:RecordField Name="End" Type="Date" />
                            <ext:RecordField Name="RealEnd" Type="Date" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>

        <Listeners>
            <AfterEdit Fn="afterEdit" />
        </Listeners>

        <ColumnModel ID="ColumnModel20" runat="server">
            <Columns>
                <ext:Column ColumnID="SprintProject" Header="Projeto" Align="Left" DataIndex="ProjectName" />
                <ext:Column ColumnID="SprintName" Header="Nome" Align="Left" DataIndex="Name" />



                <ext:Column ColumnID="SprintStatus" Header="Status" Align="Left" DataIndex="Status">
                    <Editor>
                        <ext:SelectBox
                            ID="selStatus"
                            runat="server" 
                            DisplayField="StatusName"
                            ValueField="StatusID"
                            EmptyText="Selecione um status">

                            <Store>
                                <ext:Store ID="Store2" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="StatusID">
                                            <Fields>
                                                <ext:RecordField Name="StatusID" Type="Int" />
                                                <ext:RecordField Name="StatusName" Type="String" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>            
                                </ext:Store>
                            </Store>   
                        </ext:SelectBox>
                    </Editor>
                </ext:Column>



                <ext:Column ColumnID="SprintOwner" Header="Recurso" Align="Left" DataIndex="Owner">
                    <Editor>
                        <ext:SelectBox
                            ID="selDevelopers"
                            runat="server" 
                            DisplayField="DeveloperName"
                            ValueField="DeveloperID"
                            EmptyText="Selecione um recurso">

                            <Store>
                                <ext:Store ID="Store3" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="DeveloperID">
                                            <Fields>
                                                <ext:RecordField Name="DeveloperID" Type="Int" />
                                                <ext:RecordField Name="DeveloperName" Type="String" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>            
                                </ext:Store>
                            </Store>   
                        </ext:SelectBox>
                    </Editor>
                </ext:Column>



                <ext:DateColumn ColumnID="SprintBegin" Header="Data de início" Align="Center" DataIndex="Begin"  Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



                <ext:DateColumn ColumnID="SprintEnd" Header="Previsão de término" Align="Center" DataIndex="End" Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



                <ext:DateColumn ColumnID="SprintRealEnd" Header="Data de término" Align="Center" DataIndex="RealEnd" Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



            </Columns>
        </ColumnModel>

        <View>
            <ext:GroupingView   SplitHandleWidth="10" 
                                runat="server"
                                ForceFit="true"
                                MarkDirty="false"
                                ShowGroupName="false"
                                EnableNoGroups="true"
                                HideGroupedColumn="true" ID="ctl222" />
        </View>

</ext:GridPanel>

Situation Overview

I'm using Ext.NET GridPanel to display a list of projects which has tasks (i call it Sprints) inside it assigned to some user and a status. So I get this kind of relation:

enter image description here

SprintOwner -> UserID
SprintStatus -> SprintStatusID

In my GridPanel I display my sprints grouped by projects and I use the relationships to show their names instead of their IDs (SprintStatusName and UserName). It's in portuguese but I find it useful to show:

enter image description here

In this order I have Name, Status and the SprintOwner and I can edit it all.

The problem

In Status and SprintOwner I have a comboBox which value is associated with IDs. Once I edit it, the grid updates my database and render the data again, but instead of showing the names, it shows the value (IDs) like this:

enter image description here

How can I make it show their names again?

Hence my Page_Load method

Dim db As New ProjectManagerDataContext

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
        ' Retorna as sprints do banco de dados
        ProjectsStore.DataSource = From sp In db.Sprints _
                            Select New With { _
                                .ID = sp.SprintID, _
                                .Name = sp.SprintName, _
                                .ProjectName = "[" & sp.Project.ProjectGroup1.ProjectGroupName & "] " & sp.Project.ProjectName, _
                                .Status = sp.SprintStatus1.SprintStatusName, _
                                .Owner = sp.User.UserName, _
                                .BeginDate = sp.SprintBegin, _
                                .EndDate = sp.SprintEnd, _
                                .RealEnd = sp.SprintRealEnd}
        ProjectsStore.DataBind()

        Store2.DataSource = From ss In db.SprintStatus _
                            Select New With { _
                                .StatusID = ss.SprintStatusID, _
                                .StatusName = ss.SprintStatusName}
        Store2.DataBind()

        Store3.DataSource = (From u In db.Users _
                             Select New With { _
                                .DeveloperName = u.UserName, _
                                .DeveloperID = u.UserID})
        Store3.DataBind()


    End If

End Sub

[EDITED]

And my .asp:

<ext:GridPanel 
        ID="grdProjects"
        runat="server"
        AutoHeight="true" 
        EnableColumnMove="false" 
        Collapsible="false"
        AnimCollapse="true"
        StripeRows="true" 
        Title="Projetos" >

        <Store>
            <ext:Store ID="ProjectsStore" runat="server" GroupField="ProjectName">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ProjectName" Type="String" />
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" Type="String" />
                            <ext:RecordField Name="Status" Type="String" />
                            <ext:RecordField Name="Owner" Type="String" />
                            <ext:RecordField Name="Begin" Type="Date" />
                            <ext:RecordField Name="End" Type="Date" />
                            <ext:RecordField Name="RealEnd" Type="Date" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>

        <Listeners>
            <AfterEdit Fn="afterEdit" />
        </Listeners>

        <ColumnModel ID="ColumnModel20" runat="server">
            <Columns>
                <ext:Column ColumnID="SprintProject" Header="Projeto" Align="Left" DataIndex="ProjectName" />
                <ext:Column ColumnID="SprintName" Header="Nome" Align="Left" DataIndex="Name" />



                <ext:Column ColumnID="SprintStatus" Header="Status" Align="Left" DataIndex="Status">
                    <Editor>
                        <ext:SelectBox
                            ID="selStatus"
                            runat="server" 
                            DisplayField="StatusName"
                            ValueField="StatusID"
                            EmptyText="Selecione um status">

                            <Store>
                                <ext:Store ID="Store2" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="StatusID">
                                            <Fields>
                                                <ext:RecordField Name="StatusID" Type="Int" />
                                                <ext:RecordField Name="StatusName" Type="String" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>            
                                </ext:Store>
                            </Store>   
                        </ext:SelectBox>
                    </Editor>
                </ext:Column>



                <ext:Column ColumnID="SprintOwner" Header="Recurso" Align="Left" DataIndex="Owner">
                    <Editor>
                        <ext:SelectBox
                            ID="selDevelopers"
                            runat="server" 
                            DisplayField="DeveloperName"
                            ValueField="DeveloperID"
                            EmptyText="Selecione um recurso">

                            <Store>
                                <ext:Store ID="Store3" runat="server">
                                    <Reader>
                                        <ext:JsonReader IDProperty="DeveloperID">
                                            <Fields>
                                                <ext:RecordField Name="DeveloperID" Type="Int" />
                                                <ext:RecordField Name="DeveloperName" Type="String" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>            
                                </ext:Store>
                            </Store>   
                        </ext:SelectBox>
                    </Editor>
                </ext:Column>



                <ext:DateColumn ColumnID="SprintBegin" Header="Data de início" Align="Center" DataIndex="Begin"  Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



                <ext:DateColumn ColumnID="SprintEnd" Header="Previsão de término" Align="Center" DataIndex="End" Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



                <ext:DateColumn ColumnID="SprintRealEnd" Header="Data de término" Align="Center" DataIndex="RealEnd" Format="dd/MM/yyyy">
                    <Editor>
                        <ext:DateField Format="dd/MM/yyyy" runat="server" />
                    </Editor>
                </ext:DateColumn>



            </Columns>
        </ColumnModel>

        <View>
            <ext:GroupingView   SplitHandleWidth="10" 
                                runat="server"
                                ForceFit="true"
                                MarkDirty="false"
                                ShowGroupName="false"
                                EnableNoGroups="true"
                                HideGroupedColumn="true" ID="ctl222" />
        </View>

</ext:GridPanel>

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

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

发布评论

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

评论(1

最舍不得你 2025-01-15 17:58:37

我必须看看如何配置 Store ReaderGridPanel Columns 以确定到底出了什么问题。以下示例应该会有所帮助,它演示了类似的场景,并且可用于对代码进行故障排除。

示例

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        // Owners

        var owners = new List<Person>();

        var billy = new Person
        {
            ID = 1,
            Name = "Billy"
        };

        var frank = new Person 
        {
                ID = 2,
                Name = "Frank"
        };

        var jane = new Person
        {
            ID = 3,
            Name = "Jane"
        };

        owners.AddRange(new Person[] { billy, frank, jane });

        this.strOwners.DataSource = owners;
        this.strOwners.DataBind();


        // Projects

        var projects = new List<Project>();

        projects.AddRange(new Project[] { 
            new Project { 
                ID = 1,
                Name = "Project A",
                Owner = billy
            },
            new Project {
                ID = 2,
                Name = "Project B",
                Owner = frank
            },
            new Project {
                ID = 3,
                Name = "Project C",
                Owner = jane
            }
        });

        this.strProjects.DataSource = projects;
        this.strProjects.DataBind();
    }

    public class Project
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public Person Owner { get; set; }
    }

    public class Person
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
</script>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
    <ext:ResourceManager runat="server" />

    <ext:GridPanel 
        runat="server" 
        Title="Example" 
        Height="350" 
        Width="500"
        AutoExpandColumn="Owner">
        <Bin>
            <ext:Store ID="strOwners" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Bin>
        <Store>
            <ext:Store ID="strProjects" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="OwnerID" ServerMapping="Owner.ID" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>
        <ColumnModel runat="server">
            <Columns>
                <ext:Column Header="ID" DataIndex="ID" />
                <ext:Column Header="Name" DataIndex="Name" />
                <ext:Column ColumnID="Owner" Header="Owner" DataIndex="OwnerID">
                    <Renderer Handler="return strOwners.getById(value).data.Name;" />
                    <Editor>
                        <ext:ComboBox 
                            runat="server" 
                            StoreID="strOwners"
                            DisplayField="Name"
                            ValueField="ID"
                            />
                    </Editor>
                </ext:Column>
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
</form>
</body>
</html>

希望这有帮助。

I'd have to see how you Store Reader and GridPanel Columns are configured to determine exactly what is going wrong. The following sample should be helpful at it demonstrates a similar scenario and can be used to troubleshoot your code.

Example

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        // Owners

        var owners = new List<Person>();

        var billy = new Person
        {
            ID = 1,
            Name = "Billy"
        };

        var frank = new Person 
        {
                ID = 2,
                Name = "Frank"
        };

        var jane = new Person
        {
            ID = 3,
            Name = "Jane"
        };

        owners.AddRange(new Person[] { billy, frank, jane });

        this.strOwners.DataSource = owners;
        this.strOwners.DataBind();


        // Projects

        var projects = new List<Project>();

        projects.AddRange(new Project[] { 
            new Project { 
                ID = 1,
                Name = "Project A",
                Owner = billy
            },
            new Project {
                ID = 2,
                Name = "Project B",
                Owner = frank
            },
            new Project {
                ID = 3,
                Name = "Project C",
                Owner = jane
            }
        });

        this.strProjects.DataSource = projects;
        this.strProjects.DataBind();
    }

    public class Project
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public Person Owner { get; set; }
    }

    public class Person
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
</script>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
    <ext:ResourceManager runat="server" />

    <ext:GridPanel 
        runat="server" 
        Title="Example" 
        Height="350" 
        Width="500"
        AutoExpandColumn="Owner">
        <Bin>
            <ext:Store ID="strOwners" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Bin>
        <Store>
            <ext:Store ID="strProjects" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="ID">
                        <Fields>
                            <ext:RecordField Name="ID" Type="Int" />
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="OwnerID" ServerMapping="Owner.ID" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
        </Store>
        <ColumnModel runat="server">
            <Columns>
                <ext:Column Header="ID" DataIndex="ID" />
                <ext:Column Header="Name" DataIndex="Name" />
                <ext:Column ColumnID="Owner" Header="Owner" DataIndex="OwnerID">
                    <Renderer Handler="return strOwners.getById(value).data.Name;" />
                    <Editor>
                        <ext:ComboBox 
                            runat="server" 
                            StoreID="strOwners"
                            DisplayField="Name"
                            ValueField="ID"
                            />
                    </Editor>
                </ext:Column>
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
</form>
</body>
</html>

Hope this helps.

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