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

How to get the preview string?

7 Answers 228 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 06 Nov 2010, 07:11 AM
Hi,

Does the RadFilter control provide any function to return the filter string? for example:

(
ShipCity
= 'Irvine' AND OrderDate = '11/8/2010 12:00:00 AM')

I tried SaveSettings but it returns a unreadable string.

Additionally, if I have a string, how can I recreate the filter using my string? Is there any API I can use?

Thanks and have a great day.
Bruce

7 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 09 Nov 2010, 05:04 PM
Hi Bruce,

There is no property in the current version of RadFilter that returns the string representation of the filter clause. You can modify and get reference to the RadFilter expressions using RootGroup property and from there access the expressions, filter functions, values etc. for the filter control.
string fieldName = RadFilter1.FieldEditors[0].FieldName; // name of the field that we are filtering on
                RadFilterFunction filterFunction = RadFilter1.RootGroup.Expressions[0].FilterFunction; // the filter function that was used for filtering
                RadFilterNonGroupExpression nonGroupExpression = RadFilter1.RootGroup.FindByFieldName(fieldName); 
                RadFilterGreaterThanFilterExpression<int> expression = nonGroupExpression as RadFilterGreaterThanFilterExpression<int>;
                int value = expression.Value; //the value that we filtered on (e.g. 10250)


Kind regards,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
avdhut salvi
Top achievements
Rank 1
answered on 13 Jan 2011, 02:17 PM
I was looking for the similar functionality. It'll be great if its added in future releases.

However, there is an easy workaround to this limitation. If you observe the generated HTML, filter query is displayed in div element having class "rfPreview".

I've used a simple java-script to fetch the query & save it in server side hidden-field.
function getFilterCtrlQuery() {
    var arrDiv = document.getElementsByTagName("div"); //query is displayed in div element having class as rfPreview
 
    if (arrDiv != null) {
         for (i = 0; i < arrDiv.length; i++) {
            if (arrDiv[i].className == 'rfPreview') {
                document.getElementById('hdnQuery').value = arrDiv[i].innerText; } } }
    return true;
}
0
Brian Pratt
Top achievements
Rank 1
answered on 17 Jun 2011, 02:11 PM
This is not completely finished, but I was happy to get this far.  I still need to handle all FilterFunction states that do not have Values, but this captures most of them.  This would be applied on the ApplyExpression button click.

      /// <summary>
    /// when the RadFilter Apply Expression button is clicked
    /// </summary>
    protected void RadFilter1_ApplyExpressions(object sender, RadFilterApplyExpressionsEventArgs e)
    {
        HiddenField1.Value = "Apply";
        // this is the expression in string form (similar to the Preview String in html)
        string s = WriteExpressions(e.ExpressionRoot);
    }
 
    /// <summary>
    /// Uses reflection to get the property Value, since the expression could be of many different generic types. I always assume there is a value for now.
    /// This may not be the case depending on the FilterFunction picked, but it is a start.
    /// </summary>
    /// <param name="src">The object to the the property from</param>
    /// <param name="propName">The property name of the value you are looking for</param>
    /// <returns>the value of src.propName</returns>
    public static object GetPropValue(object src, string propName)
    {
        return src.GetType().GetProperty(propName).GetValue(src, null);
    }
 
    /// <summary>
    /// Recursive function to traverse expression groups.  You would normally start with e.ExpressionRoot.
    /// </summary>
    /// <param name="group">The expression group to start at</param>
    /// <returns>string representing this expression groups preview string </returns>
    private string WriteExpressions(RadFilterGroupExpression group)
    {
 
        string result = "("; // start this group
        // we need to know the last one to figure out if we should write the conjunction
        object last = group.Expressions[group.Expressions.Count - 1];
         
        // traverse the expressions
        foreach (var expression in group.Expressions)
        {
            if (expression is RadFilterNonGroupExpression)
            {
                // this is a regular NAME == VALUE string
                RadFilterNonGroupExpression nge = expression as RadFilterNonGroupExpression;
                result += nge.FieldName;
                result += " ";
                result += nge.FilterFunction.ToString();
                result += " ";
                result += GetPropValue(nge, "Value").ToString();
            }
            else if (expression is RadFilterGroupExpression)
            {
                // this is another group expression, recurse
                result += WriteExpressions(expression as RadFilterGroupExpression);
            }
 
            // if it is not the last, print the conjunction
            if (expression != last)
            {
                result += " ";
                result += group.GroupOperation.ToString();
                result += " ";
            }
        }
        result += ")"; // end this group
 
        return result;
    }


Thanks,
Brian
0
Mike
Top achievements
Rank 1
answered on 03 Mar 2017, 04:45 PM
Hi - I'm asking 7 years after the original post... With the latest version of Telerik ASP.NET AJAX, can I get to the preview string in the RadFilter control?
0
Mike
Top achievements
Rank 1
answered on 03 Mar 2017, 04:46 PM
Hi - I'm asking 7 years after the original post... With the latest version of Telerik ASP.NET AJAX, can I get to the preview string in the RadFilter control?
0
Mike
Top achievements
Rank 1
answered on 03 Mar 2017, 04:48 PM

Sorry - I think I posted this in the wrong place 2 times...

Hi - I'm asking 7 years after the original post... With the latest version of Telerik ASP.NET AJAX, can I get to the preview string in the RadFilter control?

0
Rumen
Telerik team
answered on 08 Mar 2017, 01:35 PM

Hello Mike,

I am afraid that the requested functionality is presently not supported by the filter component. You can file a feature request it in our feedback portal.

Regards,
Rumen
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Filter
Asked by
Bruce
Top achievements
Rank 1
Answers by
Marin
Telerik team
avdhut salvi
Top achievements
Rank 1
Brian Pratt
Top achievements
Rank 1
Mike
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or