PDA

View Full Version : Editor.Add for grid column not working on 0.7?



_Belial
Mar 24, 2009, 10:04 AM
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(PropertyI nfo 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(PropertyI nfo 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(PropertyI nfo 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(Bo olean instanceOnly, String body) +318
Coolite.Ext.Web.InnerObservable.RegisterScript(Boo lean inTop) +338
Coolite.Ext.Web.InnerObservable.ParentComponent_Be foreClientInit(Observable sender) +7
Coolite.Ext.Web.OnBeforeClientInitializedHandler.I nvoke(Observable sender) +0
Coolite.Ext.Web.Observable.OnBeforeClientInitHandl er() +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

plykkegaard
Mar 24, 2009, 10:38 AM
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

_Belial
Mar 24, 2009, 10:41 AM
Thanks Peter,

Just tried, didn't make any difference :(

plykkegaard
Mar 24, 2009, 10:59 AM
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

_Belial
Mar 24, 2009, 11:51 AM
Hi peter,

Yes tried with the ID field commented + uncommented.

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

plykkegaard
Mar 24, 2009, 12:04 PM
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

_Belial
Mar 24, 2009, 12:30 PM
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}.star tEditing(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>

plykkegaard
Mar 24, 2009, 12:51 PM
_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

http://examples1.ext.net/#/GridPanel/DataSource_Update/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

_Belial
Mar 25, 2009, 5:27 AM
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

plykkegaard
Mar 25, 2009, 6:12 AM
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