This is a migrated thread and some comments may be shown as answers.

programatically added columns do not sort or filter correctly

6 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe Kalinowski
Top achievements
Rank 1
Joe Kalinowski asked on 28 Apr 2010, 05:05 PM

I am defining several columns through the RadGrid definition in the aspx file and several columns programatically in the page load event handler. The problem is that the programatically added columns don't work with sorting or filtering. The grid reloads, but the results are not sorted/filtered. If I define the column in the RadGrid definition instead of adding them programatically, they sort and filter correctly.

Columns defined in RadGrid definition:

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="LeadDistributionId" ReadOnly="true" UniqueName="LeadDistributionId" Visible="true" />

 

 

<telerik:GridBoundColumn SortExpression="LeadDistributionType" HeaderText="Lead Distribution Type" DataField="LeadDistributionType" HeaderButtonType="TextButton" HeaderStyle-Width="150" ItemStyle-Width="150" FooterStyle-Width="150" />

 

 

<telerik:GridBoundColumn SortExpression="ProgramName" HeaderText="Program" DataField="ProgramName" HeaderButtonType="TextButton" />

 

 

<telerik:GridBoundColumn DataField="ProgramID" Visible="false" />

 

 

<telerik:GridBoundColumn SortExpression="SupplierName" HeaderText="Supplier" DataField="SupplierName" HeaderButtonType="TextButton" />

 

 

<telerik:GridBoundColumn DataField="SupplierID" Visible="false" />

 

 

<telerik:GridBoundColumn SortExpression="State" HeaderText="State" DataField="State" HeaderButtonType="TextButton" HeaderStyle-Width="150" ItemStyle-Width="150" FooterStyle-Width="150" />

 

 

<telerik:GridBoundColumn DataField="StateID" Visible="false" />

 

 

</Columns>

Columns defined programatically:

 

 

protected void Page_Load(object sender, EventArgs e)

 

{

 

// if this is the initial page request

 

 

if (!this.IsPostBack)

 

{

 

DataTable dtLeadDistributionSummary =

 

((

DataView)this.sdsLeadDistributionSummary.Select(new DataSourceSelectArguments())).ToTable();

 

 

Regex reCallCenterColumn = new Regex(LeadDistributionSummary.CallCenterColumnRegEx);

 

 

foreach (DataColumn dataColumn in dtLeadDistributionSummary.Columns)

 

{

 

// if this colummn is a call center column

 

 

if (reCallCenterColumn.IsMatch(dataColumn.ColumnName))

 

{

 

GridBoundColumn gridBoundColumn = new GridBoundColumn();

 

 

// when adding columns programatically in Page_Load event, column

 

 

// must be added to the columns collection before setting properties

 

 

this.RadGrid1.MasterTableView.Columns.Add(gridBoundColumn);

 

gridBoundColumn.UniqueName = dataColumn.ColumnName;

gridBoundColumn.DataField = dataColumn.ColumnName;

gridBoundColumn.HeaderButtonType =

GridHeaderButtonType.TextButton;

 

gridBoundColumn.HeaderStyle.Width = 150;

gridBoundColumn.ItemStyle.Width = 150;

gridBoundColumn.FooterStyle.Width = 150;

gridBoundColumn.Groupable =

true;

 

gridBoundColumn.AllowFiltering =

true;

 

 

// remove "CC-" prefix from column name for header text

 

gridBoundColumn.HeaderText = reCallCenterColumn.Replace(dataColumn.ColumnName,

"$2");

 

}

}

 

// hide grouped columns

 

 

foreach (GridGroupByExpression gridGroupByExpression in this.RadGrid1.MasterTableView.GroupByExpressions)

 

{

 

foreach (GridGroupByField gridGroupByField in gridGroupByExpression.GroupByFields)

 

{

 

this.RadGrid1.MasterTableView.GetColumnSafe(gridGroupByField.FieldName).Visible = false;

 

}

}

#region

 

expand first level

 

 

//// bind grid so items may be expanded below

 

 

//this.RadGrid1.Rebind();

 

 

//// loop through group headers

 

 

//foreach (GridGroupHeaderItem gridGroupHeaderItem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))

 

 

//{

 

 

// if (gridGroupHeaderItem.GroupIndex.Length == 1)

 

 

// {

 

 

// // expand the group

 

 

// gridGroupHeaderItem.Expanded = true;

 

 

// }

 

 

// else

 

 

// {

 

 

// gridGroupHeaderItem.Expanded = false;

 

 

// }

 

 

// Groups[gridGroupHeaderItem.GroupIndex] = gridGroupHeaderItem.Expanded;

 

 

//}

 

#endregion

 

expand first level

 

}

}

6 Answers, 1 is accepted

Sort by
0
Joe Kalinowski
Top achievements
Rank 1
answered on 28 Apr 2010, 05:25 PM
I apologize, sorting is working, only the filtering is not working.
0
Pavlina
Telerik team
answered on 29 Apr 2010, 03:43 PM
Hi Joe,

Please, have in mind that RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime. You should either create all the columns in the grid programmatically, or else define them all in the ASPX file.

Kind regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joe Kalinowski
Top achievements
Rank 1
answered on 30 Apr 2010, 05:25 PM
I have moved all columns to be created programatically. I still have the same issue with filtering. The problem appears to be related to creating the columns programatically. The only differences with the columns that do not work versus the columns that do work is that the columns that do not work are numeric and contain a bar (|) in the column name.
0
Pavlina
Telerik team
answered on 05 May 2010, 01:14 PM
Hi Joe,

Based on the supplied information, it is hard to determine what is causing the unwanted behavior. To further track the issue, it will be best if you open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with further information.

Regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joe Kalinowski
Top achievements
Rank 1
answered on 05 May 2010, 07:11 PM
I have resolved the issue. The problem was the bar (|) contained in the column names mentioned in a previous post.
0
Pavlina
Telerik team
answered on 06 May 2010, 09:09 AM
Hi Joe,

I am glad you were able to find a solution. In case you encounter problems, do not hesitate to contact us again.

All the best,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Joe Kalinowski
Top achievements
Rank 1
Answers by
Joe Kalinowski
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or