Editor.Add for grid column not working on 0.7?

  1. #1

    Editor.Add for grid column not working on 0.7?

    Hi there,

    I'm trying to create a grid programatically, all works very well until I start adding an editor to the columns, when I do that I get some errors.

    Here's the chunk of code for adding the columns

                foreach (DataColumn col in (dt.Columns))
                {
                    Coolite.Ext.Web.Column webCol = new Coolite.Ext.Web.Column();
                    webCol.Header = col.ColumnName;
                    webCol.Sortable = true;
                    webCol.DataIndex = col.ColumnName;
                    webCol.Fixed = false;
    
                    
                    Coolite.Ext.Web.TextField tfEditor = new Coolite.Ext.Web.TextField();
                    
                    // tfEditor.ID = "txtEditor_" + col.Ordinal.ToString();                    
                    webCol.Editor.Add(tfEditor);
                                    
                    gpGrid.ColumnModel.Columns.Add(webCol);
                    Coolite.Ext.Web.RecordField field = new Coolite.Ext.Web.RecordField(col.ColumnName);
                    reader.Fields.Add(field);
                }
                dsStore.Reader.Clear();
                dsStore.Reader.Add(reader);
                //dsStore.DataSource = dt;
            }
            dsStore.DataBind();
    If I comment out completely the WebCol.Editor.Add(tfEditor) line then all works well, but obviously I get no editors.

    If I leave it in I get

    <h2> Object reference not set to an instance of an object. </h2>
    
                
    
                 Description: An
    unhandled exception occurred during the execution of the current web
    request. Please review the stack trace for more information about the
    error and where it originated in the code. 
    
    
    
                 Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    
    
                Source Error: 
    
    
    
                <table bgcolor="#ffffcc" width="100%">
                   <tbody><tr>
                      <td>
                          <code>
    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of
    the exception can be identified using the exception stack trace below.</code>
    
                      </td>
                   </tr>
                </tbody></table>
    
                
    
    
                Stack Trace: 
    
    
    
                <table bgcolor="#ffffcc" width="100%">
                   <tbody><tr>
                      <td>
                          <code></code>[NullReferenceException: Object reference not set to an instance of an object.]
       Coolite.Ext.Web.ClientConfig.WriteValue(String name, Object value) +535
       Coolite.Ext.Web.ClientConfig.ToExtConfig(PropertyInfo property, Object obj, ClientConfigAttribute attr, Object defaultValue) +2903
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +133
    
    [Exception: Error during ClientConfig initialization. ClientID - Object reference not set to an instance of an object.]
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +231
       Coolite.Ext.Web.ClientConfig.Serialize(Object obj, Boolean ignoreCustomSerialization) +641
       Coolite.Ext.Web.ClientConfig.ToExtConfig(PropertyInfo property, Object obj, ClientConfigAttribute attr, Object defaultValue) +927
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +133
    
    [Exception: Error during ClientConfig initialization. Editor - Error during ClientConfig initialization. ClientID - Object reference not set to an instance of an object.]
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +231
       Coolite.Ext.Web.ClientConfig.Serialize(Object obj, Boolean ignoreCustomSerialization) +641
       Coolite.Ext.Web.ClientConfig.ToExtConfig(PropertyInfo property, Object obj, ClientConfigAttribute attr, Object defaultValue) +1893
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +133
    
    [Exception: Error during ClientConfig initialization. Columns - Error during ClientConfig initialization. Editor - Error during ClientConfig initialization. ClientID - Object reference not set to an instance of an object.]
       Coolite.Ext.Web.ClientConfig.Process(Object obj) +231
       Coolite.Ext.Web.ClientConfig.Serialize(Object obj, Boolean ignoreCustomSerialization) +641
       Coolite.Ext.Web.WebControl.get_InitialConfig() +87
       Coolite.Ext.Web.WebControl.GetClientConstructor(Boolean instanceOnly, String body) +318
       Coolite.Ext.Web.InnerObservable.RegisterScript(Boolean inTop) +338
       Coolite.Ext.Web.InnerObservable.ParentComponent_BeforeClientInit(Observable sender) +7
       Coolite.Ext.Web.OnBeforeClientInitializedHandler.Invoke(Observable sender) +0
       Coolite.Ext.Web.Observable.OnBeforeClientInitHandler() +26
       Coolite.Ext.Web.Observable.OnClientInit() +12
       Coolite.Ext.Web.WebControl.SetResources() +48
       Coolite.Ext.Web.WebControl.PreRenderAction() +436
       Coolite.Ext.Web.Container.OnPreRender(EventArgs e) +81
       System.Web.UI.Control.PreRenderRecursiveInternal() +86
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
    </td></tr></tbody></table>
    Now if I uncomment the line

    // tfEditor.ID = "txtEditor_" + col.Ordinal.ToString();
    I don't get the error, but I get a javascript null reference error instead

    <div class="errorTitle ">C is null
    <div class="errorSourceBox errorSource-exec ">
    <div class="errorSourceBox errorSource-exec ">Ext.form.Field=Ext.extend(Ext.BoxCompone...ue})}}};Ext.reg("field",Ext.form.Field);
    <a class="objectLink objectLink-sourceLink ">coolite.axd?9936 (line 123</a>)
    I saw a similar thread but that said that the problem was fixed (was with property grids in that instance) in 0.7, but i'm already running 0.7 and getting this problem?

    Any ideas?

    Thanks in advance


  2. #2

    RE: Editor.Add for grid column not working on 0.7?

    Try setting the ColumnId property on the column object

    Sample from my own sourcecode:
    public static ext.Column CreateColumn(string dataIndex, string header, int width)
    {
        ext.Column col = new ext.Column();
        col.ColumnID = dataIndex;
        col.DataIndex = dataIndex;
        col.Header = header;
        col.Width = width;
        return col;
    }
    hth/Peter
  3. #3

    RE: Editor.Add for grid column not working on 0.7?

    Thanks Peter,

    Just tried, didn't make any difference :(

  4. #4

    RE: Editor.Add for grid column not working on 0.7?

    Did you also set the ID for the textfield (uncomment the line) when you tried?

    A bit odd as it is working in my project
    I am also using codebehind for grids/columns editors etc

    - Peter
  5. #5

    RE: Editor.Add for grid column not working on 0.7?

    Hi peter,

    Yes tried with the ID field commented + uncommented.

    Are you using textfields as well when doing yours? or diff field types?

  6. #6

    RE: Editor.Add for grid column not working on 0.7?



    Only difference is the naming convention used for the id's of the editor (textfields)

    This is my method which creates the gridcolumns

    public ext.ColumnCollection GridColumns(bool isAjaxRequest, HtmlForm form)
    {
     ext.Column _col;
     ext.CheckColumn _chkCol;
     ext.TextField _text;
     // SqlDataSource _sqlDS;
     // ext.Store _store;
     // ext.JsonReader _reader;
     ext.ComboBox _combo;
     ext.ColumnCollection _columns = new ext.ColumnCollection();
    
    
     // Configuration.ColumnDefCollection _colDefs = table.ColumnDefs;
    
    
     _colDefs.Sort();
    
    
     foreach (Configuration.ColumnDef c in _colDefs)
     {
      if (_keyColumn.Length == 0)
      {
       if (c.Identity)
       {
        _keyColumn = c.Name;
       }
      }
    
    
      switch (c.DataType)       // Build the ColumnCollection (grid)
      {
       case System.TypeCode.Boolean:
        _chkCol = new ext.CheckColumn();     // We need to use a checkbox column to all available properties
        _chkCol.ColumnID = c.Name;
        _chkCol.DataIndex = c.Name;
        _chkCol.Header = c.Label;
        _chkCol.Align = ext.Alignment.Center;
        _chkCol.Editable = ((!c.ReadOnly) &amp;&amp; (_cellEditing));     // Do we allow editing
        _columns.Add(_chkCol);        // Add it to the ColumnCollection (datagrid)
        
        break;
    
       case System.TypeCode.Int16:
       case System.TypeCode.Int32:
       case System.TypeCode.Int64:
        _col = Utils.PageUtils.CreateColumn(c.Name, c.Label, c.Width);
        if ((!c.ReadOnly) &amp;&amp; (_cellEditing))
        {
         _text = new ext.TextField();
         _text.ID = "txt" + c.Name;
         _text.MaskRe = "/[0-9]/";     // Filter keystrokes
         _col.Editor.Add(_text);
        }
        _columns.Add(_col);  // Build the ColumnCollection (datagrid)
        break;
    
    
       default:
        _col = Utils.PageUtils.CreateColumn(c.Name, c.Label, c.Width);
        if ((!c.ReadOnly) &amp;&amp; (_cellEditing))
        {
         Configuration.QueryDef q = c.Query;
         if (q.LookUpQuery().Length != 0)
         {
          if (!isAjaxRequest)
          {
           _combo = Utils.PageUtils.CreateComboBoxEditor(form, Configuration.Config.GetConnectionString(), c);
           _col.Editor.Add(_combo);
          }
         }
         else
         {
          _text = new ext.TextField();
          _text.ID = "txt" + c.Name;
          _col.Editor.Add(_text);
         }
        }
        _col.Tooltip = c.Tooltip;  // Add the tooltip to the column header
        _columns.Add(_col);    // Build the ColumnCollection (datagrid)
        break;
      }
     }  // end colDefs.ForEach
     return _columns;
    }
    The columnDefCollection is a collection if column definitions stored as an XML file (serialized to disk)

    - Peter
  7. #7

    RE: Editor.Add for grid column not working on 0.7?

    Strange, still not working.

    Could I trouble you to post how your grid is defined in the aspx file please? Here's mine

    <ext:GridPanel Border="true" Header="True" ID="gpGrid" runat="server" StoreID="dsStore" Height="600" TrackMouseOver="true" StripeRows="true">
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="false" runat="server">
                    <Listeners>
                    
                        <RowSelect Handler="#{btnDelete}.enable();" />
                        <RowDeselect Handler="if (!#{gpGrid}.hasSelection()) {#{btnDelete}.disable();}" />
                    </Listeners>
                </ext:RowSelectionModel>
            </SelectionModel>
            <View>
                <ext:GridView ID="GridView1" runat="server" IDMode="Legacy">
                    <GetRowClass FormatHandler="False" Handler="" />
                </ext:GridView>
            </View>
            <LoadMask ShowMask="true" />
            <SaveMask ShowMask="true" />                        
            <BottomBar>
                <ext:PagingToolBar ID="PagingToolBar1" runat="server" PageSize="25"  />
            </BottomBar>  
            <Buttons>            
                <ext:Button ID="Button4" runat="server" Text="Add" AutoPostBack="false" Icon="Add">
                    <Listeners>
                        <Click Handler="var rowIndex = #{gpGrid}.addRecord(); #{gpGrid}.getView().focusRow(rowIndex); #{gpGrid}.startEditing(rowIndex, 0);" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button5" runat="server" Text="Insert" AutoPostBack="false" Icon="Add">
                    <Listeners>
                        <Click Handler="#{gpGrid}.insertRecord(0, {});#{gpGrid}.getView().focusRow(0);#{gpGrid}.startEditing(0, 0);" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="btnDelete" runat="server" Text="Delete" AutoPostBack="false" Icon="Delete" Disabled="true">
                    <Listeners>
                        <Click Handler="#{gpGrid}.deleteSelected();if (!#{gpGrid}.hasSelection()) {#{btnDelete}.disable();}" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button6" runat="server" Text="Save" AutoPostBack="false" Icon="Disk">
                    <Listeners>
                        <Click Handler="#{gpGrid}.save();" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button7" runat="server" Text="Clear" AutoPostBack="false" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{gpGrid}.clear();if (!#{gpGrid}.hasSelection()) {#{btnDelete}.disable();}" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button8" runat="server" Text="Refresh" AutoPostBack="false" Icon="ArrowRefresh">
                    <Listeners>
                        <Click Handler="#{gpGrid}.reload();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
  8. #8

    RE: Editor.Add for grid column not working on 0.7?

    _Belial (3/24/2009)
    Strange, still not working.
    Could I trouble you to post how your grid is defined in the aspx file please?
    Hmm there's a bug when you're using handlers in the gridview

    http://forums.ext.net/showthread.php?1776

    Don't know if it applies to your situation?

    My code is based upon this example

    https://examples1.ext.net/#/GridPane...SqlDataSource/

    I can upload the code which generates my gridpanel, but it's done in codebehind and extended to support gridfilters, a contextmenu, toolbars etc
    Could be slightly more confusing than actual helpful :)

    rgds/Peter
    Last edited by geoffrey.mcgill; Feb 21, 2011 at 3:54 AM.
  9. #9

    RE: Editor.Add for grid column not working on 0.7?

    Thanks Peter,

    Still having no joy, wondered if it was a problem with textfields being used as editors, so tried combo's, exactly same problem. Even recreated the whole grid + code behind from scratch, get the same, very odd indeed.


    Anyone else have any suggestions at all?


    P.S : It works fine if i define the fields+ editor in teh aspx btw, this only seems to be a problem when creating all the columns at runtime.


    Thanks


  10. #10

    RE: Editor.Add for grid column not working on 0.7?

    Hmm I am creating viewport, borderlayout etc in codebehind
    At one point I tried to move the above controls to markup (aspx file) but I ran into some runtime errors

    I am creating columns etc based upon an xml file (serialized objects/collections) and it's working ok

Similar Threads

  1. [CLOSED] Grid Combo Editor - Make drop-down wider than column
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 02, 2011, 3:05 PM
  2. [CLOSED] Grid Column Editor
    By Vasudhaika in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: May 23, 2011, 11:43 AM
  3. Replies: 3
    Last Post: Mar 08, 2011, 7:36 AM
  4. [CLOSED] Grid Editor with Summary in data column [1.0]
    By pdcase in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 07, 2011, 9:13 AM
  5. Replies: 0
    Last Post: Jan 24, 2011, 12:10 PM

Posting Permissions