I have a client who wants to be able to select more than one type of option when filtering against a particular column in a radgrid. Say they want to see all accounts that are either High or Low Risk Levels. However, they also want regular radgrid filtering for the other columns in this grid such as accountant name.
I created a listbox with a hidden radfilter to accommodate selecting multiple options for the risk level: Select say, "Low" and "High" at the same time. However, if I want to also filter down to a specific accountant, the radfilter expression is no longer applied.
Is there a way to use both the radfilter, AND the radgrid's filter controls? Thanks! I am attaching my code. Thank you for your help.
ASP.NET:
VB.NET:
I created a listbox with a hidden radfilter to accommodate selecting multiple options for the risk level: Select say, "Low" and "High" at the same time. However, if I want to also filter down to a specific accountant, the radfilter expression is no longer applied.
Is there a way to use both the radfilter, AND the radgrid's filter controls? Thanks! I am attaching my code. Thank you for your help.
ASP.NET:
<
script
type
=
"text/javascript"
>
function onRequestStart(sender, args) {
//alert(args.get_eventTarget().toString())
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0) {
args.set_enableAjax(false);
}
else {
args.set_enableAjax(true);
}
}
</
script
>
<
br
/>
<
br
/>
<
asp:Table
runat
=
"server"
ID
=
"table1"
Width
=
"873px"
>
<
asp:TableHeaderRow
>
<
asp:TableHeaderCell
ColumnSpan
=
"2"
>Accounts By Risk Level</
asp:TableHeaderCell
>
</
asp:TableHeaderRow
>
<
asp:TableRow
>
<
asp:TableCell
ColumnSpan
=
"2"
>
To narrow down the report by risk level, select an option in the box below. To see more than one risk level, press and hold the "Ctrl" key on your keyboard while selecting the levels you wish to view. To see all levels, click the "View All Risk Levels" button.
</
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
Width
=
"20%"
>
<
telerik:RadListBox
ID
=
"RadListBox1"
runat
=
"server"
Skin
=
"WebBlue"
Width
=
"100px"
SelectionMode
=
"Multiple"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadListBoxItem
runat
=
"server"
Text
=
"Low"
Value
=
"Low"
/>
<
telerik:RadListBoxItem
runat
=
"server"
Text
=
"Medium"
Value
=
"Medium"
/>
<
telerik:RadListBoxItem
runat
=
"server"
Text
=
"High"
Value
=
"High"
/>
<
telerik:RadListBoxItem
runat
=
"server"
Text
=
"Reimbursement"
Value
=
"Reimbursement"
/>
<
telerik:RadListBoxItem
runat
=
"server"
Text
=
"Unassigned"
Value
=
"Unassigned"
/>
</
Items
>
</
telerik:RadListBox
>
<
br
/>
<
telerik:RadButton
ID
=
"RadButton1"
runat
=
"server"
Text
=
"View All Risk Levels"
Skin
=
"WebBlue"
>
</
telerik:RadButton
>
</
asp:TableCell
>
</
asp:TableRow
>
<
asp:TableRow
>
<
asp:TableCell
ColumnSpan
=
"2"
>
<
br
/><
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"True"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
Skin
=
"WebBlue"
width
=
"100%"
CellSpacing
=
"0"
PageSize
=
"10"
>
<
ExportSettings
Excel-Format
=
"ExcelML"
ExportOnlyData
=
"True"
FileName
=
"AccountsByRiskLevel"
></
ExportSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
ShowAddNewRecordButton
=
"False"
ShowRefreshButton
=
"False"
ShowExportToExcelButton
=
"True"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"name"
FilterControlAltText
=
"Filter Muni_Name column"
HeaderText
=
"Name"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Account"
FilterControlAltText
=
"Filter Account column"
HeaderText
=
"CID"
UniqueName
=
"Account"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Accountant"
FilterControlAltText
=
"Filter Accountant column"
HeaderText
=
"FEAD Accountant"
UniqueName
=
"Accountant"
>
</
telerik:GridBoundColumn
>
<
telerik:GridDateTimeColumn
DataField
=
"end_date"
FilterControlAltText
=
"Filter end_date column"
HeaderText
=
"End Date"
UniqueName
=
"end_date"
DataFormatString
=
"{0:d}"
PickerType
=
"DatePicker"
FilterControlWidth
=
"125px"
>
<
HeaderStyle
Width
=
"160px"
/>
<
ItemStyle
Width
=
"160px"
/>
</
telerik:GridDateTimeColumn
>
<
telerik:GridBoundColumn
DataField
=
"risk_level"
FilterControlAltText
=
"Filter risk column"
HeaderText
=
"Risk Level"
UniqueName
=
"risk"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_WebBlue"
></
HeaderContextMenu
>
</
telerik:RadGrid
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
Skin
=
"WebBlue"
width
=
"873px"
>
</
telerik:RadAjaxLoadingPanel
>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
<
br
/>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
Visible
=
"false"
>
<
telerik:RadFilter
ID
=
"RadFilter1"
runat
=
"server"
FilterContainerID
=
"RadGrid1"
Enabled
=
"false"
ShowApplyButton
=
"false"
>
</
telerik:RadFilter
>
</
asp:Panel
>
<
br
/>
<
telerik:RadAjaxManager
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
/>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadListBox1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadListBox1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadListFilter1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadButton1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadButton1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadListBox1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadListFilter1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
VB.NET:
Private
Sub
RadGrid1_NeedDataSource(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Handles
RadGrid1.NeedDataSource
connSql.ConnectionString = sqlConn.ToString()
Dim
poSqlCom
As
New
SqlCommand(
"dbo.AccountRiskLevel"
, connSql)
poSqlCom.CommandType = CommandType.StoredProcedure
Dim
adapter
As
New
SqlDataAdapter(poSqlCom)
Try
adapter.Fill(dtRisk)
Catch
ex
As
Exception
'lblResult.Text = ex.Message
If
connSql.State = ConnectionState.Open
Then
connSql.Close()
End
If
End
Try
RadGrid1.DataSource = dtRisk
End
Sub
Protected
Sub
RadGrid1_ItemDataBound(sender
As
Object
, e
As
GridItemEventArgs)
Handles
RadGrid1.ItemDataBound
If
TypeOf
e.Item
Is
GridFilteringItem
Then
Dim
filteringItem
As
GridFilteringItem = TryCast(e.Item, GridFilteringItem)
filteringItem.Cells(8).Controls(0).Visible =
False
filteringItem.Cells(8).Controls(1).Visible =
False
End
If
End
Sub
Private
Sub
RadListBox1_SelectedIndexChanged(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
RadListBox1.SelectedIndexChanged
RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.
Or
Dim
count
As
Integer
= 0
RadFilter1.RootGroup.Expressions.Clear()
For
Each
item
In
RadListBox1.SelectedItems
If
count = 0
Then
Dim
expr1
As
New
RadFilterEqualToFilterExpression(Of
String
)(
"risk_level"
)
expr1.Value = item.Value
RadFilter1.RootGroup.AddExpression(expr1)
ElseIf
count = 1
Then
Dim
expr2
As
New
RadFilterEqualToFilterExpression(Of
String
)(
"risk_level"
)
expr2.Value = item.Value
RadFilter1.RootGroup.AddExpression(expr2)
ElseIf
count = 2
Then
Dim
expr3
As
New
RadFilterEqualToFilterExpression(Of
String
)(
"risk_level"
)
expr3.Value = item.Value
RadFilter1.RootGroup.AddExpression(expr3)
ElseIf
count = 3
Then
Dim
expr4
As
New
RadFilterEqualToFilterExpression(Of
String
)(
"risk_level"
)
expr4.Value = item.Value
RadFilter1.RootGroup.AddExpression(expr4)
ElseIf
count = 4
Then
Dim
expr5
As
New
RadFilterEqualToFilterExpression(Of
String
)(
"risk_level"
)
expr5.Value = item.Value
RadFilter1.RootGroup.AddExpression(expr5)
End
If
count = count + 1
Next
RadFilter1.FireApplyCommand()
End
Sub
Private
Sub
RadButton1_Click(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
RadButton1.Click
RadFilter1.RootGroup.Expressions.Clear()
RadFilter1.FireApplyCommand()
RadListBox1.ClearSelection()
End
Sub
#End Region