I have a radGrid with a FilterTemplate containing a radComboBox with CheckBoxes=true.
I want to preselect a number of items in the radComboBox but that doesn't seem to work inside the filtertemplate (while it works just fine for the radComboBox outside a grid)
The grid columns and template are created in server side code, the data is loaded via a pagemethod.
I minimized my code down to this:
gridtest.aspx.cs:
gridtest.aspx
I expect the radComboBox filter in Field1 to have it's 2 items checked, but that doesn't seem to be the case, although they were checked in the code.
I want to preselect a number of items in the radComboBox but that doesn't seem to work inside the filtertemplate (while it works just fine for the radComboBox outside a grid)
The grid columns and template are created in server side code, the data is loaded via a pagemethod.
I minimized my code down to this:
gridtest.aspx.cs:
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Telerik.Web.UI;using System.Web.Services;namespace SMTX.Common.Web { public partial class gridtest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) initGrid(); } public void initGrid() { Forms.BL.EntityClasses.ViewEntity objView = Forms.BL.MyCode.ViewFactory.fetch(18); RadGrid1.AllowFilteringByColumn = true; GridBoundColumn objCol = new GridBoundColumn { AllowFiltering = true, DataField = "Field1", HeaderText = "Field1", DataType = Type.GetType("System.String"), FilterTemplate = new FilterTemplateCombo() }; RadGrid1.Columns.Add(objCol); objCol = new GridBoundColumn { AllowFiltering = false, DataField = "Field2", HeaderText = "Field2", DataType = Type.GetType("System.String") }; RadGrid1.Columns.Add(objCol); ScriptManager.RegisterStartupScript(this, this.GetType(), "CallGetView", @"setTimeout(function() {radGrid_Init();} , 1000);", true); } [WebMethod] public static List<dataContainer> GetData(List<GridFilterExpression> p_lstFilterExpressions) { List<dataContainer> lstData = getDataForGrid(p_lstFilterExpressions); return lstData; } public static List<dataContainer> getDataForGrid(List<GridFilterExpression> p_lstFilterExpressions) { List<dataContainer> lstData = dataContainer.getTestData(); List<String> lstFilterValues = null; if (p_lstFilterExpressions.Count > 0) lstFilterValues = p_lstFilterExpressions[0].FieldValue.Split(new []{"||"}, StringSplitOptions.RemoveEmptyEntries).ToList(); if (lstFilterValues == null) return lstData; else return lstData.Where(r => lstFilterValues.Contains(r.Field1)).ToList(); } } public class dataContainer { public Object Field1 { get; set; } public Object Field2 { get; set; } public static List<dataContainer> getTestData() { List<dataContainer> lstToRetrun = new List<dataContainer>(); lstToRetrun.Add(new dataContainer { Field1 = "Name1", Field2 = "Name1field2" }); lstToRetrun.Add(new dataContainer { Field1 = "Name2", Field2 = "Name2field2" }); return lstToRetrun; } } public class FilterTemplateCombo : ITemplate { object m_objDataSource; public FilterTemplateCombo() { m_objDataSource = new[] { "Name1", "Name2" }; } public void InstantiateIn(Control objContainer) { RadComboBox objCombobox = new RadComboBox(); objContainer.Controls.Add(objCombobox); objCombobox.DataSource = m_objDataSource; objCombobox.DataBind(); objCombobox.OnClientItemChecked = "RadGrid_ComboBoxMultiFilterCommand"; objCombobox.CheckBoxes = true; foreach (RadComboBoxItem objItem in objCombobox.Items) objItem.Checked = true; } }}gridtest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="gridtest.aspx.cs" Inherits="SMTX.Common.Web.gridtest" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><html><body> <form id="form1" runat="server"> <ajax:ToolkitScriptManager ID="MyToolkitScriptManager" runat="server" EnablePageMethods="true" /> <telerik:RadGrid ID="RadGrid1" runat="server"> <ClientSettings> <ClientEvents OnCommand="RadGrid_Command" /> </ClientSettings> </telerik:RadGrid> <telerik:RadScriptBlock runat="server"> <script type="text/javascript"> function radGrid_Init() { var tableView = $find("RadGrid1").get_masterTableView(); PageMethods.GetData(tableView.get_filterExpressions().toList(), RadGrid_Update); } function RadGrid_Command(sender, args) { args.set_cancel(true); var filterExpressions = sender.get_masterTableView().get_filterExpressions(); PageMethods.GetData(filterExpressions.toList(), RadGrid_Update); } function RadGrid_ComboBoxMultiFilterCommand(sender, args) { var gridTableView = sender.get_parent().get_parent().get_masterTableView(); var arr_objItems = sender.get_checkedItems(); if (arr_objItems.length > 0) { var strData = ""; for (var i = 0; i < arr_objItems.length; i++) strData += "||" + arr_objItems[i].get_value(); gridTableView.filter("Field1", strData, Telerik.Web.UI.GridFilterFunction.Custom); } else { gridTableView.filter("Field1", "", Telerik.Web.UI.GridFilterFunction.NoFilter); } } function RadGrid_Update(result) { var tableView = $find("RadGrid1").get_masterTableView(); tableView.set_dataSource(result); tableView.dataBind(); } </script> </telerik:RadScriptBlock> </form></body></html>I expect the radComboBox filter in Field1 to have it's 2 items checked, but that doesn't seem to be the case, although they were checked in the code.