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

Custom filter

2 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M. R.
Top achievements
Rank 1
M. R. asked on 31 Jul 2012, 03:13 PM
Hello,

I am trying to implement the following custom filter: rather than looking for "Contains", that can return irrelevant results, it would look for "Contains Whole Word Only" through that specific column.
Please advise.

Regards,
M.R.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Aug 2012, 05:03 AM
Hi,

I guess you want to remove the FilterFunction 'Contains' and provide a custom FilterFunction 'Contains Whole Word Only' which filters like 'EqualTo'.

C#:
protected void RadGrid1_Init(object sender, EventArgs e)
{
    GridFilterMenu menu = RadGrid1.FilterMenu;
    for (int i = menu.Items.Count - 1; i >= 0; i--)
    {
        if (menu.Items[i].Text == "Contains")
        {
            menu.Items[i].Text = "Contains the whole word";
        }
    }
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair filterPair = (Pair)e.CommandArgument;
        if (filterPair.First.ToString() == "Contains")
        {
            filterPair.First = "EqualTo";
        }
    }
}

Thanks,
Shinu.
0
M. R.
Top achievements
Rank 1
answered on 01 Aug 2012, 02:32 PM
The filter I would like to implement is not same as "Contains" or "EqualTo". It is in a way similar to "Contains" but searches by whole word. This is an example:

Let's say my grid has a column called "Description", storing the company name:
1. General Merchandising Inc
2. Bob Chandler Services Inc.
3. Adler Merchandising Sys. Inc.
4. Bobby Shandler - ABC
5. Tom & Hellen Hand Flowers

If I filter by the word "hand", then "Contains" returns all 5 descriptions above (because 'hand' is also a substring); this is not very helpful from an user point of view. 
An "EqualTo" filter returns no results (because there is no company called "hand")
The function I want to inplement, "Contains Whole Word Only" would return one result:
5. Tom & Hellen Hand Flowers

I would also like to suggest to Telerik team to implement this feature in a future version of grid because it makes perfect sense to filter by a whole word. This would eliminate any irrelevant results.

Thank you,
M.R.
Tags
Grid
Asked by
M. R.
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
M. R.
Top achievements
Rank 1
Share this question
or