[CLOSED] Create dynamic columns grid and store.

  1. #1

    [CLOSED] Create dynamic columns grid and store.

    Hi guys,


    Is possible create a dynamic grid?
    The columns and rows are unknown.

    In control grid the asp.net I set datasource is work well. How do I get the ext grid?

    This code below work well in my windows forms application:

    public DataTable MontaColunasGrid(List<documento> documentos)
            {
               
                DataTable dt = new DataTable();
    
                dt.Columns.Add("id");
    
                //Monta Coluna
                foreach (var doc in documentos)
                {
                    foreach (var item in doc.documento_indice)
                    {
                        if (!dt.Columns.Contains(item.indice.nome))
                            dt.Columns.Add(item.indice.nome);
                    }
                }
    
                foreach (var doc in documentos)
                {
                    var i = 1;
                    DataRow row = dt.NewRow();
                    row[0] = doc.id;
                    foreach (var item in doc.documento_indice)
                    {
                        row[i] = item.valor;
                        i++;
                    }
                    dt.Rows.Add(row);
                }
                return dt;
            }
    Populate store ext:

     [DirectMethod]
            public void PreencheStoreDocumento(List<documento> documentos)
            {            
                Store storeDocumento = this.GridPanelDocumento.GetStore();            
                storeDocumento.DataSource = MontaColunasGrid(documentos);
                storeDocumento.DataBind();
            }
    My problem is in the store I have defined the columns.
    I have to do anything dynamic.

    Do you have any examples like that? Our any suggestion?

    Thanks .
    Last edited by Daniil; Jun 10, 2011 at 7:16 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Why don't you use the same approach as with datatable (you add Columns to datatable)?
    Add column to the grid (and add field to the store) when you add a column to datatable
    Please investigate the following sample how to add column/fields during ajax request
    https://examples1.ext.net/#/GridPane...e_Reconfigure/
  3. #3
    Ok Vladimir.

    Please, mark as solved.
  4. #4
    Sorry, more question, please.

    I can do this?

     public void MontaColunasGrid(List<documento> documentos)
            {
                DataTable dt = new DataTable();
                               
                //Monta Coluna
                foreach (var doc in documentos)
                {
                    foreach (var item in doc.documento_indice)
                    {
                        if (!dt.Columns.Contains(item.indice.nome))
                        {
                            dt.Columns.Add(item.indice.nome);
                            this.GridPanelDocumento.ColumnModel.Columns.Add(new Column { DataIndex = "valor", Header = item.indice.nome }); 
                        }
                            
                    }
                }
     
                foreach (var doc in documentos)
                {
                    var i = 0;
                    DataRow row = dt.NewRow();
                    row[0] = doc.id;
                    foreach (var item in doc.documento_indice)
                    {
                        row[i] = item.valor;
                        i++;
                    }
                    dt.Rows.Add(row);
                }
    
                this.Store1.DataSource = dt;
                this.Store1.DataBind();
    
                if (X.IsAjaxRequest)
                {
                    this.Store1.Set("sortInfo", null);
                    this.Store1.Set("multiSortInfo", null);
                    this.GridPanelDocumento.Reconfigure();
                }
                
            }
    <Store>
                                            <ext:Store ID="Store1" runat="server" OnSubmitData="StoreDocumento_Submit">
                                                <DirectEventConfig IsUpload="true" />                                            
                                                <Reader>
                                                    <ext:JsonReader>
                                                        <Fields>
                                                           <ext:RecordField Name="valor" Type="String"/>                                                  
                                                        </Fields>
                                                    </ext:JsonReader>                                                 
                                                </Reader>
                                            </ext:Store>
                                        </Store>
    The columns and rows are created, but the rows are empty.

    Any suggestion?

Similar Threads

  1. [CLOSED] how to export few columns from grid store to excel?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 28, 2012, 8:32 PM
  2. Replies: 12
    Last Post: Sep 20, 2011, 2:33 PM
  3. Replies: 0
    Last Post: Mar 04, 2011, 6:46 AM
  4. [CLOSED] Create dynamic grid from XML
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 07, 2010, 1:43 PM
  5. Replies: 1
    Last Post: Feb 24, 2010, 3:05 PM

Tags for this Thread

Posting Permissions