[CLOSED] Custom grid with addtional columns

  1. #1

    [CLOSED] Custom grid with addtional columns

    Hello.

    I have created a class, which inherited from the GridPanel. In the javascript constructor of this grid, I populated default config of the grid. I want to create a AdditionalColumns property, which should works like ColumnModel. For that I right the following structure

    public class MyGrid: GridPanel
    {
    
                    [Meta]
            [ConfigOption]
            [DefaultValue(0)]
            [NotifyParentProperty(true)]
            public override ConfigOptionsCollection ConfigOptions
            {
                get
                {
    
                    // This check is need for dynamic control loading, using LoadControl
                    //if (this.AdditionalColumns.Columns.Count > 0)
                    //{
                        list.Add("additionalColumns", new ConfigOption("additionalColumns", new SerializationOptions("additionalColumns", typeof(LazyControlJsonConverter)), null, this.AdditionalColumns));
                    //}
                    return list;
                }
            }
    
            private GridHeaderContainer additionalColumns;
    
    
            [Meta]
            [ConfigOption("columns", typeof(LazyControlJsonConverter))]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [Description("Column definitions which define all columns that appear in this grid. Each column definition provides the header text for the column, and a definition of where the data for that column comes from.")]
            public virtual GridHeaderContainer AdditionalColumns
            {
                get
                {
                    if (this.additionalColumns == null)
                    {
                        this.additionalColumns = new GridHeaderContainer();
                        this.Controls.Add(this.additionalColumns);
                        this.LazyItems.Add(this.additionalColumns);
                    }
    
                    return this.additionalColumns;
                }
            }
    }
    This control is used in different cases:
    a) Standard markup without additional columns
    b) Standard markup with additional columns
    c) a) + b) for case, when MyGrid is a part of the complex control, which is dynamically loaded using LoadControl method.

    In variant mentioned above this control rises error in case c), because the following config is generated
    {
         xtype: 'mygrid',
         additionalColumns:  /*there is no eny object here*/
    }
    I tried to add
    if (this.AdditionalColumns.Columns.Count > 0)
    check, which is commented above. Then case c) is going to work, but case a) failed with the error

    "ItemTag validation (_tkn_134): Reference token (phContent_phToolsContent_ctl191_ClientInit) was not found."

    Could you, please, suggest how can I fix my code to avoid errors for all cases?

    Best regards.
    Last edited by Daniil; Dec 23, 2013 at 11:28 AM. Reason: [CLOSED]
  2. #2
    Try this
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
                var addCm = this.AdditionalColumns; // to ensure that AdditionalColumns is created in time (not during serialization)
            }
  3. #3
    This works for me. Thank you.

Similar Threads

  1. [CLOSED] Fastest way to get a grid's columns?
    By jchau in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Nov 06, 2013, 2:54 PM
  2. Replies: 0
    Last Post: Sep 16, 2013, 8:26 AM
  3. Replies: 0
    Last Post: Aug 23, 2012, 11:55 PM
  4. Add other columns to Property Grid
    By huzzy143 in forum 1.x Help
    Replies: 0
    Last Post: Sep 24, 2011, 12:46 PM
  5. [CLOSED] Link in Grid defined by 2 Grid Columns
    By macap in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 23, 2009, 7:47 AM

Posting Permissions