[CLOSED] ComboBox in GridPanel

  1. #1

    [CLOSED] ComboBox in GridPanel

    Hi all,

    referring to examples -> DataSource Update -> SqlDataSource there is the field 'Region' as a combobox.
    I'm working with a similar task, the only difference is I'm using an object data source.
    What if the field points to the ID of a separate entity/table 'REGIONS', for example TB_REGIONS?

    | ID_REGION | REGION_NAME

    At editing mode, I could successfully load the combo with the list of values passed through out the Store object, but then the field shows the ID and not the description of my Object, according to the example the ID_REGION and not REGION_NAME.

    When loading the grid the field looks empty. The grid doesn't show the 'Description'

    Store for combo:

    
    <ext:Store runat="server" ID="TipoTemplateStore" DataSourceID="XpoDataSourceTemplateType">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Oid" />
                        <ext:RecordField Name="Description" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
    The Grid Reader:

    
    <ext:Store ID="StoreTemplateMail" DataSourceID="XpoDataSourceTemplateMail" runat="server">
                                                            <Reader>
                                                                <ext:JsonReader ReaderID="Oid">
                                                                    <Fields>
                                                                        <ext:RecordField Name="Oid" Type="Int" />
                                                                        <ext:RecordField Name="TipoTemplate" Type="Auto" />
                                                                    </Fields>
                                                                </ext:JsonReader>
                                                            </Reader>
                                                        </ext:Store>
    The grid:

    
    <ext:GridPanel ID="GridPanelTemplateMail" AutoWidth="true" EnableViewState="true"
                                                            AutoHeight="true" runat="server" StoreID="StoreTemplateMail" Title="Archivio Template Mail"
                                                            Icon="Email">
                                                            <ColumnModel ID="ColumnModel1" runat="server">
                                                                <Columns>
                                                                    <ext:Column ColumnID="clmOid" Hideable="false" Header="ID" Sortable="true" DataIndex="Oid" />
                                                                    
                                                                        <Editor>
                                                                            <ext:ComboBox ID="cbTipoTemplate" 
                                                                                            EnableViewState="true"
                                                                                            runat="server" 
                                                                                            ForceSelection="true"
                                                                                            StoreID="TipoTemplateStore" 
                                                                                            DisplayField="Description" 
                                                                                            ValueField="Oid">
                                                                           </ext:ComboBox>
                                                                        </Editor>
                                                                    </ext:Column>
                                                                    
                                                                </Columns>
                                                            </ColumnModel>
                                                            
                                                        </ext:GridPanel>
    About the Grid Reader I would write in the RecordField Name: TipoTemplate.Description

    Thanx

    Matteo
  2. #2

    RE: [CLOSED] ComboBox in GridPanel

    Hi Matteo,

    If I correct understood you then your problem next: you have combobox as editor in cell. After editing you have ID (ValueField) in cell. But you want to return Description (DisplayField).

    If my assumption is correct then you can use one field for ValueField and DisplayField because the combo always return value to cell (not display field)

     <ext:ComboBox ID="cbTipoTemplate" 
          EnableViewState="true"
          runat="server" 
          ForceSelection="true"
          StoreID="TipoTemplateStore" 
          DisplayField="Description" 
          ValueField="Description">
    </ext:ComboBox>
    If I misunderstood you then please give me more details about your problem
    Vladimir Shcheglov
    Sr. Developer
  3. #3

    RE: [CLOSED] ComboBox in GridPanel


    Hi Vladimir,

    I attached a sample project in which I print two grids, the Coolite GridPanel and, below in the page,
    the ASP.NET GridView.

    In the GridView you can see what I want to achieve with the Coolite GridPanel.
    I'm referring to the ComboBox.

    If usefull it could be an example to add to the Examples page.

    I hope my sample is clear, please let me know.

    Dlls have to be added.

    Thank you

    Matteo
  4. #4

    RE: [CLOSED] ComboBox in GridPanel

    Hi Matteo,

    I analayzed you project

    1. For combobox need to set TriggerAction="All"
    2. Your Department field is complex object. By default the complex object skipping on serialization. You can set SerializationMode="Complex" for Store and then to add renderer to Department column, like this

    <ext:Column DataIndex="DepartmentId" Header="Department" ColumnID="clmDepartment" Width="240">
         <Renderer Fn="departmentRenderer" />
          ................
    </ext:Column>
    
    and js code
    
        <script type="text/javascript">
            var departmentRenderer = function(value) {            
                return value.Name;
            }
        </script>
    But it is works if your GridPanel is read only (with editing will be problem)

    3. For solving your request I made next:
    - Add DepartmentId to Employee class, so it will be passed to serialization
        public int DepartmentId
        {
            get { return this.Department != null ? this.Department.Oid : -1; }
        }
    - Change record field name from Department to DepartmentId
    - Change DataIndex in column from Department to DepartmentId
    - Add renderer to this column
             <Renderer Fn="departmentRenderer" />
             //js code of renderer
             <script type="text/javascript">
                var departmentRenderer = function(value) {
                   //Please note that instead StoreCombo need use real ClientID of StoreCombo control
                   //Just in this simple example the ID and ClientID are same
                   var r = StoreCombo.getById(value);
    
                   if (Ext.isEmpty(r)) {
                       return "";
                   }
                
                   return r.data.Name;
               }
            </script>
    The changed project has been attached


    Vladimir Shcheglov
    Sr. Developer
  5. #5

    RE: [CLOSED] ComboBox in GridPanel

    Hi Vladimir,

    very clear! It works fine.

    Thanks a lot

    Matteo
  6. #6

    RE: [CLOSED] ComboBox in GridPanel

    Hi Vladimir,

    How can I get both DisplayField and ValueField? In the attached example I can't get DisplayField value for ComboBox if I need to insert new record. Can you help me?

    Regards,

    Yauhen

Similar Threads

  1. Replies: 4
    Last Post: Nov 30, 2011, 5:25 AM
  2. [CLOSED] Combobox in gridpanel
    By tansu in forum 1.x Premium Help
    Replies: 2
    Last Post: Jun 06, 2011, 9:43 AM
  3. Replies: 2
    Last Post: May 05, 2011, 10:16 AM
  4. [CLOSED] GridPanel ComboBox Clear Value
    By bethc in forum 1.x Premium Help
    Replies: 3
    Last Post: Sep 25, 2009, 4:49 AM
  5. Replies: 6
    Last Post: Mar 20, 2009, 5:39 PM

Posting Permissions