Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
Multi-column sorting with multi-line editor
posted

Build: 13.1.20131.2107

In my webdatagrid, I programmatically populate all the columns. I had multiline texteditorprovider for all text fields. Now I had a problem after I add the sorting behaviour. Whenever, I sort a column, it is working the first time. However, it is broken the second time. It generate the following exception.

Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at Infragistics.Web.UI.GridControls.Sorting.AddHeaderImgToCaption(GridField column, SortDirection direction)
at Infragistics.Web.UI.GridControls.Sorting.BehaviorEvents_PreRender(Object sender)
at Infragistics.Web.UI.GridControls.GridBehaviorEvents.RenderingContentHandler.Invoke(Object sender)
at Infragistics.Web.UI.GridControls.GridRenderer.RenderContents(HtmlTextWriter writer)
at Infragistics.Web.UI.Framework.RunBot.HandleRenderContents(HtmlTextWriter writer, RendererBase renderer)
at Infragistics.Web.UI.GridControls.WebDataGrid.GetRenderHTML()
at Infragistics.Web.UI.GridControls.WebDataGrid.CallbackRender(CallbackObject callbackObject)
at Infragistics.Web.UI.Framework.RunBot.CallbackRenderRecursive(CallbackObject callbackObject)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at Infragistics.Web.UI.Framework.RunBot.RenderPageCallBack(HtmlTextWriter writer, Control control)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

<The following code is used to generate the columns>

private void CreateColumns(DataTable theWholeTable, string tableName, int columnWidth)
        {
            //create editing core behaviour
            TableDetailGrid.Behaviors.CreateBehavior<Activation>();
            TableDetailGrid.Behaviors.CreateBehavior<EditingCore>();
            TableDetailGrid.Behaviors.EditingCore.AutoCRUD = false;
            TableDetailGrid.Behaviors.EditingCore.BatchUpdating = true;
            TableDetailGrid.Behaviors.EditingCore.Enabled = true;
            TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<CellEditing>();
 
            //create an editor provider
            var textprovider = new TextEditorProvider(ID = "MultilineTextProvider");
            textprovider.EditorControl.TextMode = TextBoxMode.MultiLine;
            TableDetailGrid.EditorProviders.Add(textprovider);
 
            //create RowAdding behaviour
            TableDetailGrid.Behaviors.EditingCore.Behaviors.Add(
            TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<RowAdding>());
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.EditModeActions.EnableOnActive = true;
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.EditModeActions.MouseClick = EditMouseClickAction.Single;
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.Enabled = true;
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.Alignment = AddNewRowAlignment.Top;
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowAdding.AddNewRowClientEvents.EnteringEditMode = "AddRow_EnteringEditMode_CancelEventIfReadOnly";
            
            //create RowDeleting behaviour
            TableDetailGrid.Behaviors.EditingCore.Behaviors.Add(
                TableDetailGrid.Behaviors.EditingCore.Behaviors.CreateBehavior<RowDeleting>());
            TableDetailGrid.Behaviors.EditingCore.Behaviors.RowDeleting.Enabled = true;
 
            //get readonly column names
            var readOnlyColumnNames = GetReadOnlyColumnNamesByTable(tableName);
 
            //create sorting behaviour
            var sortingBehaviour = TableDetailGrid.Behaviors.CreateBehavior<Sorting>();
            sortingBehaviour.SortingMode = SortingMode.Multi;
 
            foreach (DataColumn column in theWholeTable.Columns)
            {
                var theColumn = new BoundDataField(true);
                theColumn.Key = column.ColumnName;
                theColumn.Header.Text = column.Caption;
                theColumn.DataFieldName = column.ColumnName;
                theColumn.DataType = "System.String";
                theColumn.Width = columnWidth;
                TableDetailGrid.Columns.Add(theColumn);
 
                //create column settings
                var settingColumn = new EditingColumnSetting();
                
                settingColumn.ColumnKey = column.ColumnName;
                settingColumn.ReadOnly =
                    (readOnlyColumnNames.Contains(column.ColumnName, StringComparer.InvariantCultureIgnoreCase) ||
                     string.Equals(column.ColumnName, Session["PrimaryKeyName"].ToString(), StringComparison.InvariantCultureIgnoreCase));
                if (string.Equals(tableName, "dbo.CustomColumn"StringComparison.InvariantCultureIgnoreCase) &&
                    string.Equals(column.ColumnName, "SourceColumn"StringComparison.InvariantCultureIgnoreCase))
                {
                    settingColumn.EditorID = textprovider.ID;
                }
 
                ////create sorting column settings
                sortingBehaviour.SortedColumns.Add(TableDetailGrid.Columns[column.ColumnName], Infragistics.Web.UI.SortDirection.Ascending);
 
                TableDetailGrid.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings.Add(settingColumn);
            }
        }

<This is the configuration of the webdatagrid in the aspx>
<ig:WebDataGrid ID="TableDetailGrid" runat="server" ClientIDMode="Static" Height="100%" Width="100%" EnableAjax="False" 
				OnRowAdding="TableDetailGridRowAdding" OnRowUpdating="TableDetailGridRowUpdating" OnRowsDeleting="TableDetailGridRowDeleting">
				<AjaxIndicator Location="MiddleCenter" />
					<Behaviors>
					   <%-- <ig:Paging PagerAppearance="Bottom" PageSize="10" Enabled="true" />--%>
						<ig:Filtering Alignment="Top" Visibility="Visible" Enabled="true" FilterType="ExcelStyleFilter">
						</ig:Filtering>
						<ig:ColumnResizing Enabled="true">
							<ColumnSettings>
								<ig:ColumnResizeSetting EnableResize="true" />
							</ColumnSettings>
						</ig:ColumnResizing>
						<ig:Activation Enabled="True"/>
						<ig:Selection RowSelectType="Multiple" Enabled="true" ColumnSelectType="Single" CellClickAction="row" />
						<ig:RowSelectors RowNumbering="true" Enabled="true" />
						<ig:VirtualScrolling ScrollingMode="Virtual" DataFetchDelay="500" RowCacheFactor="3" ThresholdFactor="0.5" Enabled="true" />
					</Behaviors>
					<EmptyRowsTemplate>
						<div id="divAttention" style="text-alignleft;">
							<br />
							<img alt="Attention" src="/Images/attention.png" />
						</div>
					</EmptyRowsTemplate>
					<ErrorTemplate>
						<div style="text-alignleft">
							<br />
							<img alt="Error" src="/Images/error.png" />
							<%= GetGlobalResourceObject("DataManager_English","ErrorTemplateMessage"%>
					</ErrorTemplate>
			</ig:WebDataGrid>

Can someone please help let me know why the textprovider does not work with the Sorting behaviour? Thank you so much.
  • 49378
    posted

    Hello Andrew,

    Thank you for posting in the community.

    As the columns, updating behavior and the updating column settings are being created dynamically in this scenario, are they being recreated on each postback ? Does it make a difference in this case if they are instantiated only on the initial load ? A small sample application showing the issue in practice would be greatly appreciated and would allow me to examine this matter in more detail.