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

How to customise filter operators

4 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tung
Top achievements
Rank 1
Tung asked on 06 Mar 2017, 10:42 AM

Hi

 

I want to customise the available filter operators and change the default operator in my RadGridView

 

For example in a string column, I'd like to default to 'Starts With' instead of 'Contains' and want to remove the 'Ends With' operator.

 

Thanks

Tung

4 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 07 Mar 2017, 03:28 PM
Hi Tung, 

Thank you for writing.

The default filters are determined according to the type of the column. In order to change the default one you would add an empty filter descriptor having the required operator: 
radGridView1.Columns[0].FilterDescriptor = new Telerik.WinControls.Data.FilterDescriptor(null, Telerik.WinControls.Data.FilterOperator.StartsWith, null);

Regarding your other question, you can handle the ContextMenuOpening event of the grid and remove the Ends with menu item: 
private void radGridView1_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
    RadMenuItem item = e.ContextMenu.Items.Where(i => i.Text == "Ends with").FirstOrDefault() as RadMenuItem;
    if (item != null)
    {
        e.ContextMenu.Items.Remove(item);
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
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.
0
Tung
Top achievements
Rank 1
answered on 08 Mar 2017, 12:38 PM

Hi Hrist

I managed to remove the filter operators but I'm having issues with changing the filter operator.

I can create the filter descriptor with a StartsWith operator then I tried to set it as the FilterDescriptor for radGridView1:MasterTemplate.Columns['field'] then radGridView1:Columns['field'] like your example but I get an error message about chained attribute expression.

I have four columns I want to change but it changes only three of them and the operator doesn't change from Contains to Starts With until I put the mouse cursor over the grid.

I'm using Progress Openedge so I don't know if that might be a factor.

Thanks

Tung

0
Tung
Top achievements
Rank 1
answered on 08 Mar 2017, 02:40 PM

Hi Hristo

Ignore my last post. I had methods for the FilterChanged and FilterChanging events to handle batching ourselves and they were interferring with your code example.

I unsubscribe those events while I set the empty filter and resubscribe afterwards and it works fine now.

Thanks for your help

Tung

0
Hristo
Telerik team
answered on 09 Mar 2017, 05:39 PM
Hi Tung,

Thank you for the update.

As I understand currently you have the issue resolved.

Should you have further questions do not hesitate to write back.

Regards,
Hristo
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
GridView
Asked by
Tung
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Tung
Top achievements
Rank 1
Share this question
or