I have created a Grid with filtering using the RadGrid with the following markup
with the custom filtering column as such:
As per your example in Grid -> Filtering Template Columns. I am using Telerik version 2009.3.1208.35.
The page render's and the grid display full of data. I filter on every column except the custom column and the filtering works great. When I select a value from the drop down, the grid empties and no records are displayed.
Any idea's?
Thanks,
Luke
<
telerik:RadGrid
ID
=
"RadGrid1"
Width
=
"99%"
OnNeedDataSource
=
"Grid_NeedDataSource"
AllowFilteringByColumn
=
"True"
AllowSorting
=
"True"
PageSize
=
"20"
ShowFooter
=
"True"
AllowPaging
=
"True"
runat
=
"server"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
Skin
=
"Office2007"
>
<
GroupingSettings
CaseSensitive
=
"false"
/>
<
MasterTableView
ShowHeadersWhenNoRecords
=
"true"
AllowFilteringByColumn
=
"True"
ShowFooter
=
"True"
DataKeyNames
=
"OffenseTypeId"
TableLayout
=
"Fixed"
ClientDataKeyNames
=
"OffenseTypeId, StateCode, Description"
>
<
Columns
>
<
telerik:GridClientSelectColumn
HeaderStyle-Width
=
"30px"
/>
<
telerik:GridBoundColumn
DataField
=
"StateCode"
HeaderText
=
"VCC Code"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
ShowFilterIcon
=
"true"
FilterControlWidth
=
"70%"
>
<
HeaderStyle
Width
=
"120px"
/>
</
telerik:GridBoundColumn
>
<
custom:OffenseModifierFilteringColumn
DataField
=
"ModifierDescription"
HeaderText
=
"Offense Modifier"
AllowFiltering
=
"true"
FilterControlWidth
=
"90%"
>
<
HeaderStyle
Width
=
"200px"
/>
<
ItemTemplate
>
<%# Eval("ModifierDescription")%>
</
ItemTemplate
>
</
custom:OffenseModifierFilteringColumn
>
<
telerik:GridBoundColumn
DataField
=
"Description"
HeaderText
=
"Description"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
ShowFilterIcon
=
"true"
FilterControlWidth
=
"95%"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"OffenseStatute"
HeaderText
=
"Statute"
AutoPostBackOnFilter
=
"true"
CurrentFilterFunction
=
"Contains"
ShowFilterIcon
=
"true"
FilterControlWidth
=
"70%"
>
<
HeaderStyle
Width
=
"120px"
/>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
<
ClientEvents
OnRowSelected
=
"RowSelected"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
with the custom filtering column as such:
/// <summary>
/// Custom Filtering column for the SelectOffense
/// </summary>
public
class
OffenseModifierFilteringColumn : GridTemplateColumn
{
/// <summary>
/// Setups the filter controls.
/// </summary>
/// <param name="cell">The cell.</param>
protected
override
void
SetupFilterControls(TableCell cell)
{
var rcBox =
new
RadComboBox
{
ID =
"DropDownList1"
,
AutoPostBack =
true
,
DataTextField = DataField,
DataValueField = DataField
};
rcBox.SelectedIndexChanged += rcBox_SelectedIndexChanged;
var table = GetDataTable();
var row = table.NewRow();
row[DataField] =
""
;
table.Rows.InsertAt(row, 0);
rcBox.DataSource = table;
cell.Controls.Add(rcBox);
}
/// <summary>
/// Sets the current filter value to control.
/// </summary>
/// <param name="cell">The cell.</param>
protected
override
void
SetCurrentFilterValueToControl(TableCell cell)
{
if
(!(CurrentFilterValue ==
""
))
{
((RadComboBox)cell.Controls[0]).Items.FindItemByText(CurrentFilterValue).Selected =
true
;
}
}
/// <summary>
/// Gets the current filter value from control.
/// </summary>
/// <param name="cell">The cell.</param>
/// <returns></returns>
protected
override
string
GetCurrentFilterValueFromControl(TableCell cell)
{
var currentValue = ((RadComboBox)cell.Controls[0]).SelectedItem.Value;
CurrentFilterFunction = (currentValue !=
""
) ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter;
return
currentValue;
}
/// <summary>
/// Handles the SelectedIndexChanged event of the rcBox control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs"/> instance containing the event data.</param>
protected
void
rcBox_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
((GridFilteringItem)(((RadComboBox)sender).Parent.Parent)).FireCommandEvent(
"Filter"
,
new
Pair());
}
/// <summary>
/// Gets the filter data field.
/// </summary>
/// <returns></returns>
protected
override
string
GetFilterDataField()
{
return
DataField;
}
#region Private Members
/// <summary>
/// Gets the data table.
/// </summary>
/// <returns></returns>
public
DataTable GetDataTable()
{
var offenseModifiers = BusinessProcessManagerFactory<IOffenseTypeManager>.Instance.Get().GetOffenseModifiers();
// convert to datatable
var myDataTable = SqlTableTypeHelper.CreateTableType(offenseModifiers.Select(x => x.ModifierDescription).ToList(),
typeof
(String),
"ModifierDescription"
);
return
myDataTable;
}
#endregion
}
As per your example in Grid -> Filtering Template Columns. I am using Telerik version 2009.3.1208.35.
The page render's and the grid display full of data. I filter on every column except the custom column and the filtering works great. When I select a value from the drop down, the grid empties and no records are displayed.
Any idea's?
Thanks,
Luke