Hi,
How do i include excel like multi select filter functionality in Radgrid? Same feature is there Silverlight Radgridview but I can't use silverlight in my application. So if you can provide me with some examples to include multiselect filter functionality in Radgrid similar to Silverlight Radgridview.
Thanks
Shasanka
How do i include excel like multi select filter functionality in Radgrid? Same feature is there Silverlight Radgridview but I can't use silverlight in my application. So if you can provide me with some examples to include multiselect filter functionality in Radgrid similar to Silverlight Radgridview.
Thanks
Shasanka
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 05 Sep 2011, 03:28 PM
Hello Shekhar,
Try setting EnableHeaderContextMenu and EnableHeaderContextFilterMenu to True.
aspx:
Thanks,
Princy.
Try setting EnableHeaderContextMenu and EnableHeaderContextFilterMenu to True.
aspx:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
EnableHeaderContextFilterMenu
=
"true"
EnableHeaderContextMenu
=
"true"
>
Thanks,
Princy.
0
Shekhar
Top achievements
Rank 1
answered on 06 Sep 2011, 07:36 PM
Hi,
Thanks for the reply.
EnableHeaderContextFilterMenu shows filter options in HeaderContext menu but this doesn't show filter values with multiple selections.
Want something similar feature of silverlight RadGridView. http://demos.telerik.com/silverlight/#GridView/FirstLook
Want only multiple value selection feature for filter.
Thanks
Shekhar
Thanks for the reply.
EnableHeaderContextFilterMenu shows filter options in HeaderContext menu but this doesn't show filter values with multiple selections.
Want something similar feature of silverlight RadGridView. http://demos.telerik.com/silverlight/#GridView/FirstLook
Want only multiple value selection feature for filter.
Thanks
Shekhar
0
Kyle
Top achievements
Rank 2
Veteran
answered on 29 Apr 2013, 02:47 PM
I'd like to bump this very old thread. I, too, would like the ASP .NET AJAX RadGrid Filter to work like the Silverlight RadGrid Filter with the checkbox list.
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2013, 06:53 AM
Hi Kyle,
Please try the sample code snippet,which depicts a similar scenario.
ASPX:
C#:
Thanks,
Princy
Please try the sample code snippet,which depicts a similar scenario.
ASPX:
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnPreRender
=
"RadGrid1_PreRender"
AutoGenerateColumns
=
"False"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
EnableLinqExpressions
=
"false"
>
<
MasterTableView
EditMode
=
"InPlace"
AllowFilteringByColumn
=
"true"
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
HeaderText
=
"EmployeeID"
SortExpression
=
"EmployeeID"
UniqueName
=
"EmployeeID"
DataType
=
"System.Int32"
>
<
FilterTemplate
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
DataValueField
=
"EmployeeID"
DataTextField
=
"EmployeeID"
EmptyMessage
=
"All Types"
AllowCustomText
=
"true"
Width
=
"240px"
>
<
ItemTemplate
>
<
asp:CheckBox
runat
=
"server"
Checked
=
"true"
ID
=
"chk1"
onclick
=
"onCheckBoxClick(this)"
/>
<%# Eval("EmployeeID")%>
</
ItemTemplate
>
<
FooterTemplate
>
<
asp:Button
ID
=
"clrFilters"
runat
=
"server"
Text
=
"Clear filters"
OnClick
=
"clrFilters_Click"
/>
</
FooterTemplate
>
</
telerik:RadComboBox
>
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function onCheckBoxClick(chk) {
var text = "", values = "";
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var combo = $find('<%# ((GridItem)Container).FindControl("RadComboBox1").ClientID %>');
//get the collection of all items
var items = combo.get_items();
//enumerate all items
for (var i = 0; i <
items.get_count
(); i++) {
var
item
=
items
.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
if (chk1.checked) {
text += item.get_text() + ",";
values += item.get_value() + ",";
}
}
//remove the last comma from the string
text
=
removeLastComma
(text);
values
=
removeLastComma
(values);
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("EmployeeID," + text);
}
function removeLastComma(str) {
return str.replace(/,$/, "");
}
</
script
>
</
telerik:RadScriptBlock
>
</
FilterTemplate
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"City"
HeaderText
=
"City"
SortExpression
=
"City"
UniqueName
=
"City"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
br
/>
<
asp:Button
ID
=
"clrFilters"
runat
=
"server"
Text
=
"Clear filters"
OnClick
=
"clrFilters_Click"
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
SelectCommand="SELECT distinct [EmployeeID],[City] FROM [Employees]"></
asp:SqlDataSource
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
DefaultLoadingPanelID
=
"RadAjaxLoadingPanel1"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"clrFilters"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
Skin
=
"Default"
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>"
SelectCommand="SELECT DISTINCT [ShipCountry] FROM [Orders]"></
asp:SqlDataSource
>
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
ViewState[
"filterRawString"
] =
null
;
}
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(ViewState[
"filterRawString"
] !=
null
)
{
foreach
(GridFilteringItem item
in
RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
{
RadComboBox combo = (RadComboBox)item.FindControl(
"RadComboBox1"
);
foreach
(RadComboBoxItem comboItem
in
combo.Items)
{
if
(ViewState[
"filterRawString"
].ToString().Contains(comboItem.Text.ToString()))
{
CheckBox chk = (CheckBox)comboItem.FindControl(
"chk1"
);
chk.Checked =
true
;
}
else
{
CheckBox chk = (CheckBox)comboItem.FindControl(
"chk1"
);
chk.Checked =
false
;
}
}
}
}
}
protected
void
RadAjaxManager1_AjaxRequest(
object
sender, AjaxRequestEventArgs e)
{
string
str = e.Argument.ToString();
String query =
"SELECT DISTINCT EmployeeID, City FROM Employees WHERE EmployeeID = '"
+ str.Split(',
')[1] + "'
";
if
(str.Split(
','
)[0] ==
"EmployeeID"
)
{
for
(
int
i = 2; i < str.Split(
','
).Length; i++)
{
query = query +
" OR EmployeeID='"
+ str.Split(',
')[i] + "'
";
}
ViewState[
"filterRawString"
] = str;
RadGrid1.DataSource = GetDataTable(query);
RadGrid1.Rebind();
GridFilteringItem filterItem = RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0]
as
GridFilteringItem;
RadComboBox combo = (RadComboBox)filterItem.FindControl(
"RadComboBox1"
);
RadAjaxManager1.ResponseScripts.Add(
"$find('"
+ combo.ClientID +
"').showDropDown();"
);
}
}
public
DataTable GetDataTable(
string
query)
{
String ConnString = ConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(ConnString);
SqlDataAdapter adapter =
new
SqlDataAdapter();
adapter.SelectCommand =
new
SqlCommand(query, conn);
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return
myDataTable;
}
protected
void
RadGrid1_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e)
{
if
(ViewState[
"filterRawString"
] ==
null
)
RadGrid1.DataSource = GetDataTable(
"SELECT EmployeeID,City FROM Employees"
);
}
protected
void
clrFilters_Click(
object
sender, EventArgs e)
{
foreach
(GridColumn column
in
RadGrid1.MasterTableView.Columns)
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue =
string
.Empty;
}
RadGrid1.MasterTableView.FilterExpression =
string
.Empty;
RadGrid1.MasterTableView.Rebind();
}
Thanks,
Princy