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

Even-Odd Custom Filter

3 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Sheldon
Top achievements
Rank 2
Mark Sheldon asked on 01 Sep 2010, 02:02 PM
Is it possible to implement an Even-Odd custom filter? The following in the Grid's Item_Command event causes an
unexpected char: '%' error.


if (e.CommandName == RadGrid.FilterCommandName)
{
    Pair filterPair = (Pair)e.CommandArgument;
    if (filterPair.First.ToString() == "Custom")
    {
        string colName = filterPair.Second.ToString();
         
        TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;
        string[] values = tbPattern.Text.Split(' ');
        if (values.Length == 1)
        {
            e.Canceled = true;
            //string newFilter = "mod(" + filterPair.Second +",2)" + "=" + values[0];
            string newFilter = "(" + filterPair.Second + " % 2) ="+values[0];
            if (RadGrid1.MasterTableView.FilterExpression == "")
            {
                RadGrid1.MasterTableView.FilterExpression = newFilter;
            }
            else
            {
                RadGrid1.MasterTableView.FilterExpression = RadGrid1.MasterTableView.FilterExpression+ "AND" + newFilter;
            }
            RadGrid1.Rebind();
        }
    }

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 07 Sep 2010, 01:57 PM
Hello Mark Sheldon,

I would suggest that you set EnableLinqExpressions="false" to your RadGrid.

I hope this helps.

Regards,
Martin
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
Mark Sheldon
Top achievements
Rank 2
answered on 07 Sep 2010, 11:13 PM
Hi Martin, thanks for your assistance.

I had already tried toggling Enable Linq Expressions on and off. With Enable Linq Expressions set to false without success. The error is:
line 1:94: unexpected char: '%'
Original Query: DEFINE EXTENT xt FOR msnetDataTier.VwSelectedPrecinct; SELECT * FROM xt AS this WHERE (RecId % 2) =0


It is the same either way.

Thanks again.

m,
0
Martin
Telerik team
answered on 10 Sep 2010, 04:00 PM
Hello Mark Sheldon,

I have created a small sample that works as expected on my side - if you enter an even/odd number in the filter box and choose "custom" function, the column will show even/odd numbers only. Note that if you would like to filter the grid by more that one condition (in case you have more than one columns), you will need to modify the logic so that it correctly sets or appends the new filter expression to the one set before the command is triggered.

I hope this helps.

Kind regards,
Martin
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
Tags
Grid
Asked by
Mark Sheldon
Top achievements
Rank 2
Answers by
Martin
Telerik team
Mark Sheldon
Top achievements
Rank 2
Share this question
or