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

In and NotIn

6 Answers 33 Views
Filter
This is a migrated thread and some comments may be shown as answers.
moegal
Top achievements
Rank 1
moegal asked on 05 Apr 2013, 10:35 PM
I want to create a custom RadFilter

I want to show a dropdown(combo) but have the choices be IN or NotIN I would actually call them "In Order" and "Not In Order"

my data would look like the following.

orderID | OrderDate | ProductList
123456   04/01/2013   15,16,17,18,19

here is an image of what I am trying to do.


6 Answers, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 10 Apr 2013, 06:51 AM
Hi Marty,

You could achieve your scenario by creating a custom RadFilter editor as shown in the help article and demo below.

Additionally, you could modify the menu options by following the help article below and the sample code provided below.
function pageLoad(sender, args)
{
    var filter = $find("<%=RadFilter1.ClientID %>");
    var menu = filter.get_contextMenu();
    menu.add_showing(FilterMenuShowing);
 
    var elements = document.getElementsByTagName("a");
    for (var i = 0; i < elements.length; i++)
    {
        if (elements[i].className && elements[i].className.indexOf("rfExp") != -1 &&
            elements[i].innerHTML == "EqualTo")
        {
            elements[i].innerHTML = "In Order";
        }
        else if (elements[i].className && elements[i].className.indexOf("rfExp") != -1 &&
            elements[i].innerHTML == "NotEqualTo")
        {
            elements[i].innerHTML = "Not In Order";
        }
    }
}
 
function FilterMenuShowing(sender, args)
{
    sender.findItemByValue("EqualTo").set_text("In Order");
    sender.findItemByValue("NotEqualTo").set_text("Not In Order");
}

Regards,
Antonio Stoilkov
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
moegal
Top achievements
Rank 1
answered on 10 Apr 2013, 02:09 PM
Antonio,

thanks for the reply.

I already have been working on the interface part of the filter(Botheof the links you sent are what I have been working off of). How can I tell the query to select a value inside of the returned value?

my datasource and/or grid will have a record like the following:

ProductList
15,16,17,18,19

so my resulting filter would return 16 =  15,16,17,18,19

If I were using an operator of EqualTo then 16 would not work. Productlist in this case is  15,16,17,18,19.   I need something more like the sql IN operator. Contains would not really work either because I could have values like 15,168,177 so 16 would return true if I used contains. But it should not.

Thanks, Marty
0
Antonio Stoilkov
Telerik team
answered on 15 Apr 2013, 05:49 AM
Hi Marty,

In order to achieve your scenario you could use a Contains which is for your example ProductList 15, 16, 17, 18, 19 which could be Contains "15, " OR Contains ", 15". Note that we are currently working on improving RadFilter API so these kind of operations are easier to achieve. However, currently you should manually swap each of the Contains expression for two Contains expressions as described above in the ApplyExpressions event and applying the technique shown in the help topic below.

Regards,
Antonio Stoilkov
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
moegal
Top achievements
Rank 1
answered on 15 Apr 2013, 05:01 PM
Antonio,

thanks.  that may work.  Can you point me to a RadFilterSqlQueryProvider example.  Not sure I follow on how to replace one "contains" expression with 2 "contains" as you have explained.

Marty
0
Antonio Stoilkov
Telerik team
answered on 18 Apr 2013, 07:19 AM
Hi Marty,

I have assembled a sample page showing the desired functionality implemented. The idea is to subscribe to RadGrid ApplyExpressions event and for every RadFilterContainsFilterExpression replace it with two RadFilterContainsFilterExpression.
protected void RadFilter1_ApplyExpressions(object sender, Telerik.Web.UI.RadFilterApplyExpressionsEventArgs e)
{
    RadFilterGroupExpression rootGroupClone = new RadFilterGroupExpression();;
    for (int i = 0; i < RadFilter1.RootGroup.Expressions.Count; i++)
    {
        RadFilterContainsFilterExpression containsExpression = RadFilter1.RootGroup.Expressions[i] as RadFilterContainsFilterExpression;
        if (containsExpression != null && !containsExpression.Value.Contains(','))
        {
            RadFilterContainsFilterExpression first = new RadFilterContainsFilterExpression(containsExpression.FieldName);
            first.Value = containsExpression.Value + ", ";
            RadFilterContainsFilterExpression second = new RadFilterContainsFilterExpression(containsExpression.FieldName);
            second.Value = ", " + containsExpression.Value;
                 
            RadFilterGroupExpression group = new RadFilterGroupExpression();
            group.AddExpression(first);
            group.AddExpression(second);
            group.GroupOperation = RadFilterGroupOperation.Or;
 
            rootGroupClone.AddExpression(group);
        }
        else
        {
            rootGroupClone.AddExpression(RadFilter1.RootGroup.Expressions[i]);
        }
    }
 
    RadFilterDynamicLinqQueryProvider provider = new RadFilterDynamicLinqQueryProvider();
    provider.ProcessGroup(rootGroupClone);
    Response.Write(provider.Result);
}

Kind regards,
Antonio Stoilkov
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
moegal
Top achievements
Rank 1
answered on 18 Apr 2013, 09:31 AM
I will check it out, thanks Antonio.

Marty
Tags
Filter
Asked by
moegal
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
moegal
Top achievements
Rank 1
Share this question
or