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

[Solved] Multiple columns 'OR' Filtering

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Fernando
Top achievements
Rank 1
Fernando asked on 15 May 2013, 11:15 AM
Hi!

Isn't this suposed to work?

protected void uxGridSubscription_OnItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        var filterPair = (Pair) e.CommandArgument;
 
        switch (filterPair.Second.ToString())
        {
             
 
            case "Name":
                {
                    var filterValue = uxGridSubscription.MasterTableView.GetColumnSafe("Name").CurrentFilterValue;
                    uxGridSubscription.MasterTableView.FilterExpression = "(([Name] LIKE \'%" + filterValue + "%\') OR ([Obs] LIKE \'%" + filterValue + "%\'))";
 
                    var column2 = uxGridSubscription.MasterTableView.GetColumnSafe("Obs");
                    column2.CurrentFilterFunction = GridKnownFunction.Contains;
                    column2.CurrentFilterValue = filterValue;
                    uxGridSubscription.MasterTableView.Rebind();
                    break;
                }
     }
    }
}

This acts like 'AND' and not an 'OR'. 

Best Regards, Fernando Moreira

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 May 2013, 08:15 AM
Hello,

You could try to place this logic inside the PreRender event of RadGrid and check whether you get the desired behavior.

bool nameFiltered = false;
protected void uxGridSubscription_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
{
    var filterPair = (Pair) e.CommandArgument;
 
    switch (filterPair.Second.ToString())
    {
        case "Name":
            {
                nameFiltered=true;
            }
            break;
    }
 
}
 
protected void uxGridSubscription_PreRender(object sender, EventArgs e)
{
    if(nameFiltered)
    {
    var filterValue = uxGridSubscription.MasterTableView.GetColumnSafe("Name").CurrentFilterValue;
    uxGridSubscription.MasterTableView.FilterExpression = "(([Name] LIKE \'%" + filterValue + "%\') OR ([Obs] LIKE \'%" + filterValue + "%\'))";
 
    var column2 = uxGridSubscription.MasterTableView.GetColumnSafe("Obs");
    column2.CurrentFilterFunction = GridKnownFunction.Contains;
    column2.CurrentFilterValue = filterValue;
    uxGridSubscription.MasterTableView.Rebind();
    }
}

Regards,
Andrey
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.
Tags
Grid
Asked by
Fernando
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or