How to display texts(string) in gridpanel column when the associated database value is in int- Ext.Net?

StackOverflow https://stackoverflow.com/questions/22244329

Вопрос

I have a gridpanel with a column Status like this:

<ext:ModelField Name="Status" Type="String" />

And I have a sql table with a column Status which is int that can contain values '1' and '2' meaning 'Pending' and 'Confirmed'. Right now when I bind the gridpanel the column shows numeric values (1 or 2) but, I want to display Pending for 1 and Confirmed for 2 in the column Status. How can I do this? I am stuck.

Это было полезно?

Решение

Having an additional ModelField for the display representation is one of possible solutions.

Another is to use a Column's Renderer.

Example

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

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

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            Store store = this.GridPanel1.GetStore();
            store.DataSource = new object[] 
            { 
                new object[] { "test", "1" },
                new object[] { "test", "2" },
                new object[] { "test", "3" }
            };
        }
    }
</script>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.NET v2 Example</title>
</head>
<body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server">
            <Store>
                <ext:Store runat="server">
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="test" />
                                <ext:ModelField Name="status" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column runat="server" Text="Test" DataIndex="test" />
                    <ext:Column runat="server" Text="Status" DataIndex="status">
                        <Renderer Handler="if (value === '1') { 
                                               return 'Status 1'; 
                                           } else if (value === '2') {
                                               return 'Status 2';
                                           } else {
                                               return 'Unknown status';
                                           }" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
    </form>
</body>
</html>

Другие советы

Oh I somehow solved it by creating a partial class of the sql table and adding a property Statuss like this:

public partial class tblName
    {
        public string Statuss
        {
            get;
            set;
        }
    }

and modified the Model like

<ext:ModelField Name="Statuss" Type="String" />

Then in the databinding part I added if-else part using linq like

if(tbl_entity.Status==1)
{
   tbl_entity.Statuss = "Pending";
}
else
{
   tbl_entity.Statuss = "Confirmed";
}

For now, it somehow solved the problem but, if it's not the right way or the best way to do, your answer is always welcome. Thank you.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top