Hi,
I'm trying to create a SQL-style WHERE ColumnName IN('a', 'b', 'c') filter for one of my RadGrid columns.
In my RadGrid I have a GridBoundColumn using a FilterTemplate which has a RadComboBox with a number of CheckBoxes inside it.
This part is all working fine. What I want to do is tell the RadGrid to filter and show only the options the user has ticked in the RadComboBox's CheckBoxes.
e.g.: If the user open the ComboBoxList filter and selects A, B and D, I'd like the grid to filter and show only results in that column which are A, B or D. Is this possible with native RadGrid filtering? And if not, any ideas on the best was to achieve it?
Cheers,
Adam
I'm trying to create a SQL-style WHERE ColumnName IN('a', 'b', 'c') filter for one of my RadGrid columns.
In my RadGrid I have a GridBoundColumn using a FilterTemplate which has a RadComboBox with a number of CheckBoxes inside it.
<
telerik:GridBoundColumn
HeaderText
=
"Type"
DataField
=
"Type"
UniqueName
=
"Type"
AutoPostBackOnFilter
=
"true"
>
<
FilterTemplate
>
<
telerik:RadComboBox
ID
=
"cmbType"
runat
=
"server"
DataSource="<%# TypeFilterItems %>"
DataValueField="TypeId"
DataTextField="Title"
EmptyMessage="All"
AllowCustomText="true"
Width="130px"
OnClientDropDownClosing="FilterOnType">
<
ItemTemplate
>
<
div
class
=
"combo-item-template"
>
<
div
class
=
"clear"
>
<
asp:CheckBox
runat
=
"server"
ID
=
"chkType"
Checked
=
"true"
onclick
=
"TypeCheckBoxClick(this)"
style
=
"float:left;"
/>
<
p
class
=
"floatLeft"
><%# Eval("Title") %></
p
>
</
div
>
</
div
>
</
ItemTemplate
>
</
telerik:RadComboBox
>
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock3"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function FilterOnType(sender, args) {
var tableView = $find("<%# Container.OwnerTableView.ClientID %>");
tableView.filter("Type", text, "Custom");
}
function TypeCheckBoxClick(chk) {
var combo = $find('<%# Container.FindControl("cmbType").ClientID %>');
// Get the collection of all items
var items = combo.get_items();
text = ""; values = "";
// 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 + "_chkType");
if (chk1.checked) {
text += item.get_text() + ",";
values += item.get_value() + ",";
}
}
// Remove the last comma from the string
text
= text.replace(/,$/, "");
values
= values.replace(/,$/, "");
combo.set_text(text);
}
</script>
</
telerik:RadScriptBlock
>
</
FilterTemplate
>
</
telerik:GridBoundColumn
>
This part is all working fine. What I want to do is tell the RadGrid to filter and show only the options the user has ticked in the RadComboBox's CheckBoxes.
e.g.: If the user open the ComboBoxList filter and selects A, B and D, I'd like the grid to filter and show only results in that column which are A, B or D. Is this possible with native RadGrid filtering? And if not, any ideas on the best was to achieve it?
Cheers,
Adam