This is a migrated thread and some comments may be shown as answers.

Changing Filter Text Box to Dropdown Combobox

3 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ted
Top achievements
Rank 1
Ted asked on 18 Sep 2014, 04:25 PM
We are modifying the RAD grid for Sharepoint and are running into a problem.   We need to change the default filter text box to a drop down combo box for some of the columns like you see in the demo: http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx 

With the SharePoint control, you have to set the filter template in the GridFilteringItem class.   However, when we add the code below, the button is showing but the grid does not refresh and filter based on the combo box selection.   The filters for the other columns are working fine.   It appears that the event to filter the grid is not firing, but it is difficult to tell.

Does anyone have simple sample code or ideas that would help?

         if (e.Item is GridFilteringItem)
           {
               GridFilteringItem aSystemFilteringItem = e.Item as GridFilteringItem;
               //((Telerik.Web.UI.GridTableCell)(aSystemFilteringItem["System"])).Controls.Clear();

               Button btnTest = new Button();
               btnTest.Text ="CLick Me";
               btnTest.Click += btnTest_Click;
               ((Telerik.Web.UI.GridTableCell)(aSystemFilteringItem["System"])).Controls.Add(btnTest);

               RadComboBox aSystemFilterDropDown = new RadComboBox();
               aSystemFilterDropDown.ID = "ProcessFilterDropDown";
               aSystemFilterDropDown.Width = Unit.Pixel(150);
               aSystemFilterDropDown.Items.Add(new RadComboBoxItem("", ""));
               aSystemFilterDropDown.Items.Add(new RadComboBoxItem("CGE", "CGE"));
               //aSystemFilterDropDown.SelectedIndexChanged += aSystemFilterDropDown_SelectedIndexChanged;
               aSystemFilterDropDown.OnClientSelectedIndexChanged = "SystemIndexChanged";
               aSystemFilterDropDown.AutoPostBack = true;

               ((Telerik.Web.UI.GridTableCell)(aSystemFilteringItem["System"])).Controls.Add(aSystemFilterDropDown);

               string script = "<script type=\"text/javascript\">";
               script = script + "function SystemIndexChanged(sender, args) {alert('entered'); ";
               script = script + "var tableView = $find(\"" + ((GridItem)e.Item).OwnerTableView.ClientID + "\");";
               script = script + "tableView.filter(\"System\", args.get_item().get_value(), \"EqualTo\");";
               script = script+   "}";
               script = script + "</script>";

               LiteralControl scriptLtControl = new LiteralControl(script);
               RadScriptBlock radscript = new RadScriptBlock();
               radscript.Controls.Clear();
               radscript.Controls.Add(scriptLtControl);

               ((Telerik.Web.UI.GridTableCell)(aSystemFilteringItem["System"])).Controls.Add(radscript);

           }

3 Answers, 1 is accepted

Sort by
0
Ted
Top achievements
Rank 1
answered on 19 Sep 2014, 08:43 AM
We were able to get the filtering to work in a traditional ASP.NET page using the Telerik ASP.NET tags and are starting to compare.    Since ASP.NET tags are not supported in SharePoint, we have to get the filtering to work in the web part code behind.   There are two options in the code behind.  First, in the code above, you can create a client side call to the grid to filter it using the (RAD ClientID).filter method.   You can see in the above code that we are creating this javascript snippet in a RadScriptBlock:
​     
     script = script + "var tableView = $find(\"" + ((GridItem)e.Item).OwnerTableView.ClientID + "\");";
     script = script + "tableView.filter(\"System\", args.get_item().get_value(), \"EqualTo\");";

When we take this approach, it does not appear to run at all when you click the button.   Maybe client side scripting is not supported in SharePoint ?  If anyone has a working sample of a client side call in a SharePoint RAD grid web part, that would help.

The second approach is to do this server side by adding an event trigger to the combo box that triggers when the user selects one of the options.   We tried this as well using the following code uncommented.

//aSystemFilterDropDown.SelectedIndexChanged += aSystemFilterDropDown_SelectedIndexChanged;

When we tried this approach, the event never fired when we clicked the button.







 

0
Accepted
Marin
Telerik team
answered on 23 Sep 2014, 10:40 AM
Hi,

I have sent a runnable example in the other support ticket you have opened on the same issue. Let me know it works and if you have any other questions.

Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ted
Top achievements
Rank 1
answered on 24 Sep 2014, 10:14 AM
The code was good in that it showed how to properly register the event on the server side and proved that the event firing was working.  However, the filtering was still not working using our original server side code.   We tried different ways to set the filtering and got the following to work for us, so the issue is now resolved.   We were never able to get this working client side, but doing this server side should be fine for now.    Thank you.

this.Grid.EnableLinqExpressions = false;


void aSystemFilterDropDown_SelectedIndexChanged(object sender,
RadComboBoxSelectedIndexChangedEventArgs e)

      
{

          
if (e.Value != "")

          
{

              
string
filterExpression;

              
filterExpression = "([System] = '" + e.Value + "')";

              
this.Grid.MasterTableView.FilterExpression
= filterExpression;

              
GridColumn column = Grid.MasterTableView.GetColumnSafe("System");

              
column.CurrentFilterFunction = GridKnownFunction.EqualTo;

              
column.CurrentFilterValue = e.Value;

              
ViewState["SystemFilterValue"] = e.Value;

              
this.Grid.Rebind();

          
}

          
else

          
{

               
GridColumn column = Grid.MasterTableView.GetColumnSafe("System");

               
column.CurrentFilterFunction = GridKnownFunction.NoFilter;

               
column.CurrentFilterValue = string.Empty;

               
ViewState["SystemFilterValue"] = e.Value;

               
Grid.Rebind();

          
}

        
  

 

        


       }
Tags
Grid
Asked by
Ted
Top achievements
Rank 1
Answers by
Ted
Top achievements
Rank 1
Marin
Telerik team
Share this question
or