[CLOSED] Combobox in Gridpanel editor plugin

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Combobox in Gridpanel editor plugin

    Hi,

    Is it possible to 'extend' the following example with a combobox in the editor row?
    I would like to choose an item and use both the value (in non visible column) and the Text in the grid.
    It's probably not difficult, but can't figure it out..

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.ObjectModel" %>
    <%@ 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)
        {
            if (!X.IsAjaxRequest)
            {
                var store = this.GridPanel1.GetStore();
                
                store.DataSource = new List<object>
                {
                    new { 
                        Name = "Bill Foot", 
                        Email = "bill.foot@object.net", 
                        Start = new DateTime(2007, 2, 5), 
                        Salary = 37000, 
                        Active = true
                    },
                    new { 
                        Name = "Bill Little", 
                        Email = "bill.little@object.net", 
                        Start = new DateTime(2009, 6, 13), 
                        Salary = 53000, 
                        Active = true
                    },
                    new { 
                        Name = "Bob Jones", 
                        Email = "bob.jones@object.net", 
                        Start = new DateTime(2008, 10, 6), 
                        Salary = 70000, 
                        Active = true
                    },
                    new { 
                        Name = "Bob Train", 
                        Email = "bob.train@object.net", 
                        Start = new DateTime(2009, 5, 5), 
                        Salary = 68000, 
                        Active = true
                    },
                    new { 
                        Name = "Chris Johnson", 
                        Email = "chris.johnson@object.net", 
                        Start = new DateTime(2009, 1, 25), 
                        Salary = 47000, 
                        Active = true
                    }
                };
                
                store.DataBind();
            }
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>GridPanel with RowEditor Plugin - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
        
        <ext:XScript runat="server">
            <script type="text/javascript">
                var addEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                    
                    grid.insertRecord(0, {
                        name   : "New Guy",
                        email  : "guy@object.net",
                        start  : (new Date()).clearTime(),
                        salary : 50000,
                        active : true
                    });
                    
                    grid.getView().refresh();
                    grid.getSelectionModel().selectRow(0);
                    grid.getRowEditor().startEditing(0);
                }
                
                var removeEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                    
                    var s = grid.getSelectionModel().getSelections();
                    
                    for (var i = 0, r; r = s[i]; i++) {
                        #{Store1}.remove(r);
                    }
                }
            </script>
        </ext:XScript>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <h1>GridPanel with RowEditor Plugin</h1>
            
            <ext:GridPanel 
                ID="GridPanel1" 
                runat="server"
                Width="600"
                Height="400"
                AutoExpandColumn="name"
                Title="Employees">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="name" Mapping="Name" Type="String" />
                                    <ext:RecordField Name="email" Mapping="Email" Type="String" />
                                    <ext:RecordField Name="start" Mapping="Start" Type="Date" />
                                    <ext:RecordField Name="salary" Mapping="Salary" Type="Float" />
                                    <ext:RecordField Name="active" Mapping="Active" Type="Boolean" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <Plugins>
                    <ext:RowEditor runat="server" SaveText="Update" />
                </Plugins>
                <View>
                    <ext:GridView runat="server" MarkDirty="false" />
                </View>
                <TopBar>
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:Button runat="server" Text="Add Employee" Icon="UserAdd">
                                <Listeners>
                                    <Click Fn="addEmployee" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button runat="server" Text="Remove Employee" Icon="UserDelete">
                                <Listeners>
                                    <Click Fn="removeEmployee" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" />
                </SelectionModel>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column 
                            ColumnID="name" 
                            Header="First Name" 
                            DataIndex="name" 
                            Width="220" 
                            Sortable="true">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" />
    // Use combobox here. Show Text in grid and put value in a non visible column
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Email" DataIndex="email" Width="150">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" Vtype="email" />
                            </Editor>
                        </ext:Column>
                        <ext:DateColumn 
                            Header="Start Date" 
                            DataIndex="start" 
                            Format="MM/dd/yyyy" 
                            Width="100" 
                            Sortable="true">
                            <Editor>
                                <ext:DateField 
                                    runat="server" 
                                    AllowBlank="false" 
                                    MinDate="01.01.2006" 
                                    MinText="Can not have a start date before the Company existed." 
                                    />
                            </Editor>
                        </ext:DateColumn>
                        <ext:NumberColumn 
                            Header="Salary" 
                            DataIndex="salary" 
                            Format="$0,0.00" 
                            Width="100" 
                            Sortable="true">
                            <Editor>
                                <ext:NumberField 
                                    runat="server" 
                                    AllowBlank="false" 
                                    MinValue="1" 
                                    MaxValue="150000" 
                                    />
                            </Editor>
                        </ext:NumberColumn>
                        <ext:BooleanColumn 
                            Header="Active" 
                            DataIndex="active" 
                            Align="Center" 
                            Width="50" 
                            TrueText="Yes" 
                            FalseText="No">
                            <Editor>
                                <ext:Checkbox runat="server" />
                            </Editor>
                        </ext:BooleanColumn>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>  
    </body>
    </html>
    Thanks,

    Martin
    Last edited by geoffrey.mcgill; Jan 18, 2011 at 4:36 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please clarify ComboBox is instead of TextField or in addition to TextField?
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Please clarify ComboBox is instead of TextField or in addition to TextField?
    Instead of..

    So when adding a new item, you need to pick an item from a combobox (populated from database). Both value and text need to be added to the gridpanel. The value in a hidden column.

    Is that possible ?

    Martin
  4. #4
    Yes, it's possible.

    I'm working on an example for you.
  5. #5
    Quote Originally Posted by Daniil View Post
    Yes, it's possible.

    I'm working on an example for you.
    Thanks Daniil ! Looking forward to it..

    Martin
  6. #6
    Please investigate this example.

    Example
    <%@ Page Language="C#" %>
     
    <%@ Import Namespace="System.Collections.ObjectModel" %>
    <%@ 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)
        {
            if (!X.IsAjaxRequest)
            {
                var store = this.GridPanel1.GetStore();
                 
                store.DataSource = new List<object>
                {
                    new {
                        NameID = "1",
                        Email = "bill.foot@object.net",
                        Start = new DateTime(2007, 2, 5),
                        Salary = 37000,
                        Active = true
                    },
                    new {
                        NameID = "2",
                        Email = "bill.little@object.net",
                        Start = new DateTime(2009, 6, 13),
                        Salary = 53000,
                        Active = true
                    },
                    new {
                        NameID = "3",
                        Email = "bob.jones@object.net",
                        Start = new DateTime(2008, 10, 6),
                        Salary = 70000,
                        Active = true
                    },
                    new {
                        NameID = "4",
                        Email = "bob.train@object.net",
                        Start = new DateTime(2009, 5, 5),
                        Salary = 68000,
                        Active = true
                    },
                    new {
                        NameID = "5",
                        Email = "chris.johnson@object.net",
                        Start = new DateTime(2009, 1, 25),
                        Salary = 47000,
                        Active = true
                    }
                };
                 
                store.DataBind();
    
                store = this.ComboBox1.GetStore();
                store.DataSource = new List<object>
                {
                    new {
                        Name = "Bill Foot",
                        NameID = "1"
                    },
                    new {
                        Name = "Bill Little",
                        NameID = "2"
                    },
                    new {
                        Name = "Bob Jones",
                        NameID = "3"
                    },
                    new {
                        Name = "Bob Train",
                        NameID = "4"
                    },
                    new {
                        Name = "Chris Johnson",
                        NameID = "5"
                    },
                    new {
                        Name = "New Guy",
                        NameID = "-1"
                    }
                };
                store.DataBind();
            }
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
         
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>GridPanel with RowEditor Plugin - Ext.NET Examples</title>
         
        <ext:XScript runat="server">
            <script type="text/javascript">
                var addEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                     
                    grid.insertRecord(0, {
                        nameId   : "-1",
                        email  : "guy@object.net",
                        start  : (new Date()).clearTime(),
                        salary : 50000,
                        active : true
                    });
                     
                    grid.getView().refresh();
                    grid.getSelectionModel().selectRow(0);
                    grid.getRowEditor().startEditing(0);
                }
                 
                var removeEmployee = function () {
                    var grid = #{GridPanel1};
                    grid.getRowEditor().stopEditing();
                     
                    var s = grid.getSelectionModel().getSelections();
                     
                    for (var i = 0, r; r = s[i]; i++) {
                        #{Store1}.remove(r);
                    }
                }
                
                var nameRenderer = function (value) {
                    var r = #{ComboBox1}.getStore().getById(value);
    
                    if (Ext.isEmpty(r)) {
                        return "";
                    }
    
                    return r.data.name;
                };
            </script>
        </ext:XScript>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
             
            <h1>GridPanel with RowEditor Plugin</h1>
             
            <ext:GridPanel
                ID="GridPanel1"
                runat="server"
                Width="600"
                Height="400"
                AutoExpandColumn="name"
                Title="Employees">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="nameId" Mapping="NameID" Type="String" />
                                    <ext:RecordField Name="email" Mapping="Email" Type="String" />
                                    <ext:RecordField Name="start" Mapping="Start" Type="Date" />
                                    <ext:RecordField Name="salary" Mapping="Salary" Type="Float" />
                                    <ext:RecordField Name="active" Mapping="Active" Type="Boolean" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <Plugins>
                    <ext:RowEditor runat="server" SaveText="Update" />
                </Plugins>
                <View>
                    <ext:GridView runat="server" MarkDirty="false" />
                </View>
                <TopBar>
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:Button runat="server" Text="Add Employee" Icon="UserAdd">
                                <Listeners>
                                    <Click Fn="addEmployee" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button runat="server" Text="Remove Employee" Icon="UserDelete">
                                <Listeners>
                                    <Click Fn="removeEmployee" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" />
                </SelectionModel>
                <ColumnModel>
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column
                            ColumnID="name"
                            Header="First Name"
                            DataIndex="nameId"
                            Width="220"
                            Sortable="true">
                            <Renderer Fn="nameRenderer"/>
                            <Editor>
                                <ext:ComboBox 
                                    ID="ComboBox1" 
                                    runat="server" 
                                    ValueField="nameId" 
                                    DisplayField="name">
                                    <Store>
                                        <ext:Store runat="server">
                                            <Reader>
                                                <ext:JsonReader IDProperty="NameID">
                                                    <Fields>
                                                        <ext:RecordField Name="nameId" Mapping="NameID" />
                                                        <ext:RecordField Name="name" Mapping="Name" />
                                                    </Fields>
                                                </ext:JsonReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                </ext:ComboBox>
                             </Editor>
                        </ext:Column>
                        <ext:Column Header="Email" DataIndex="email" Width="150">
                            <Editor>
                                <ext:TextField runat="server" AllowBlank="false" Vtype="email" />
                            </Editor>
                        </ext:Column>
                        <ext:DateColumn
                            Header="Start Date"
                            DataIndex="start"
                            Format="MM/dd/yyyy"
                            Width="100"
                            Sortable="true">
                            <Editor>
                                <ext:DateField
                                    runat="server"
                                    AllowBlank="false"
                                    MinDate="01.01.2006"
                                    MinText="Can not have a start date before the Company existed."
                                    />
                            </Editor>
                        </ext:DateColumn>
                        <ext:NumberColumn
                            Header="Salary"
                            DataIndex="salary"
                            Format="$0,0.00"
                            Width="100"
                            Sortable="true">
                            <Editor>
                                <ext:NumberField
                                    runat="server"
                                    AllowBlank="false"
                                    MinValue="1"
                                    MaxValue="150000"
                                    />
                            </Editor>
                        </ext:NumberColumn>
                        <ext:BooleanColumn
                            Header="Active"
                            DataIndex="active"
                            Align="Center"
                            Width="50"
                            TrueText="Yes"
                            FalseText="No">
                            <Editor>
                                <ext:Checkbox runat="server" />
                            </Editor>
                        </ext:BooleanColumn>
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form> 
    </body>
    </html>
  7. #7
    Thanx Daniil,

    That will help me very much.

    Two small remarks. The 'new guy' value is added to the grid. (seems to me that a default value isn't supposed to be added at all) and the cancel button isn't working. The record is still added to the grid even though I've chosen 'cancel'

    Martin
  8. #8
    Quote Originally Posted by CarWise View Post
    The 'new guy' value is added to the grid. (seems to me that a default value isn't supposed to be added at all) and the cancel button isn't working.
    Not sure what's the problem... Just insert an empty record.

    Quote Originally Posted by CarWise View Post
    The record is still added to the grid even though I've chosen 'cancel'
    'Cancel' button belongs to RowEditor and cancel editing of record, not inserting. So, it needs to remove manually.
  9. #9
    Quote Originally Posted by Daniil View Post
    'Cancel' button belongs to RowEditor and cancel editing of record, not inserting. So, it needs to remove manually.
    Ah.. I was thinking that the new row wasn't added at all. So when using cancel I need tot delete the record from the grid ?

    Martin
  10. #10
    Quote Originally Posted by CarWise View Post
    Ah.. I was thinking that the new row wasn't added at all. So when using cancel I need tot delete the record from the grid ?

    Martin
    Yes, that's right.
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] RowEditor plugin and combobox editor
    By boris in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 24, 2011, 1:50 PM
  2. Replies: 6
    Last Post: Sep 22, 2011, 12:46 PM
  3. [CLOSED] GridPanel ComboBox Editor with different values per row
    By logicspeak in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 16, 2011, 6:27 AM
  4. Replies: 2
    Last Post: May 05, 2011, 10:16 AM
  5. [CLOSED] Gridpanel Combobox Editor Issue
    By ndotis in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 17, 2010, 7:06 PM

Tags for this Thread

Posting Permissions