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

RadFilter CurrentExpandedItem value

4 Answers 107 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 05 Dec 2011, 07:21 PM
I am using an external RadFilter which is not associated with any grid. I am just using the filter to get the filter expression on Apply button click. My issue is that I want to set the value in the textbox for the current expanded item to a specific text, on a button click.

I saw the following code from telerik website:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair filterPair = (Pair)e.CommandArgument;
        gridMessage1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
        TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
        gridMessage2 = "<br> Entered pattern for search: " + filterBox.Text;
    }
}

I am looking for something similar where I can get the textbox for the current expanded item and then set its value. I cannot use the above code because my RADFilter is not attached to a grid.

Once again, my scenario is:
1) user chooses a field from the list of fields in the filter
2) user then clicks a button
3) the textbox for the current expanded item should be set to, say "ABC"

Thanks

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 08 Dec 2011, 03:22 PM
Hello Christopher,

When you hit the Add Filter button the filter won't know what FilterExpression to generate unless you specify it. Also, the filter does not now for which of the FieldNames to generate the filter, unless you specify it using code. Please check out the attached sample illustrating how you can set custom value to text editor with specified expression to RadFilter and see if this works for you.

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Laura
Top achievements
Rank 1
answered on 09 Dec 2011, 09:17 PM
Hi Pavlina,

  Thanks for the response. The method used in the sample will not work for me as I want the texttbox and the filter expression to be set before the user clicks the apply button. I am looking into other ways to implement the functionality I want.

Thanks
0
Pavlina
Telerik team
answered on 14 Dec 2011, 10:20 PM
Hi Christopher,

You can refer to the forum thread below which demonstrates a similar functionality to the one you are searching for.
http://www.telerik.com/community/forums/aspnet-ajax/filter/adding-a-filter-expression-on-page-load-and-pre-populating-it.aspx

Check it out and let me know if it helps to achieve your goal.

Greetings,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Laura
Top achievements
Rank 1
answered on 15 Dec 2011, 08:40 PM

Hi Pavlina,

The method in the forum thread will not solve my issue. I had openened a ticket for the same.
This is the solution I got from telerik. It worked perfectly.



<
telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
 
        function pageLoad() {
            var filter = $find("<%=RadFilter1.ClientID %>");
            setTimeout(function () {
                var hidden = $get("HiddenField1");
                if (hidden.value != "") {
                    var tb = document.getElementsByName(hidden.value)[0];
                    tb.value = "ABC";
                }
            }, 200);
 
            filter.get_contextMenu().add_itemClicking(function (sender, args) {
                var currentExpandedItem = sender.get_attributes().getAttribute("ItemHierarchyIndex");
                var expressions = filter.get_element().getElementsByTagName("li");
                var textbox;
                for (var i = 0; i < expressions.length; i++) {
                    if (expressions[i].id.split("__")[1] == currentExpandedItem) {
                        textbox = expressions[i].getElementsByTagName("input")[0];
                        $get("HiddenField1").value = textbox.name;
                        break;
                    }
                }
            });
 
        }
    </script>
</telerik:RadCodeBlock>
<telerik:RadFilter ID="RadFilter1" FilterContainerID="RadGrid1" runat="server">
</telerik:RadFilter>
<asp:HiddenField runat="server" ID="HiddenField1" />

Thanks a lot for your help.

Christopher
Tags
Ajax
Asked by
Laura
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Laura
Top achievements
Rank 1
Share this question
or