GridViewDataColumn Filtering

2 Answers 19 Views
GridView
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Ohad asked on 07 Nov 2023, 03:51 PM

I have the following code:

<telerik:GridViewDataColumn DataMemberBinding="{Binding CreatedBy.Name}" Header="Name"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding EventObject.TextData}" Header="User Text"/>

public UserType CreatedBy { get; set; }

public object EventObject { get; set; }

in another class:

public string TextData { get; set; }

 

In the first column, there is a filter icon, and it filters correctly. However, in the second column, there is no filter icon. Could you explain why this might be and how to resolve the issue?

 

Dimitar
Telerik team
commented on 08 Nov 2023, 09:04 AM

Hi Ohad, 

I have examined this and I am wondering why the EventObject property is of type object. Can't you use a base type that contains the TextData property? For example: 

public class EventObjectBase
{
    public string TextData { get; set; }
}
public class TestEventObject : EventObjectBase
{
    public string TextData2 { get; set; }
}

I am looking forward to your reply.

 

Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 08 Nov 2023, 12:59 PM

It is of type object because EventObject may be one of many different types.

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 Nov 2023, 01:15 PM

Hi Ohad,

I have examined this and it is not supported at the moment. We have a feature request that will allow this. You can track its progress, subscribe to status changes, and add your comment to it here: Add support for sorting/filtering/grouping of the additional properties that are not present for all items.

As a workaround, you can create an object that has this property and use it for the column. I have attached a small project that shows this. 

I want to apologize for the inconvenience this is causing you.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 09 Nov 2023, 05:32 PM

Okay thanks!

Can you explain to me what I need to do so that I only have an option for Contains?

I don't want the And/Or

     private void OnFilterOperatorsLoading(object sender, FilterOperatorsLoadingEventArgs e)
        {
            if (e.Column.Header.ToString() == "A")
            {
                var notWanted = new List<FilterOperator>();

                foreach (FilterOperator eAvailableOperator in e.AvailableOperators)
                {
                    if (eAvailableOperator != FilterOperator.Contains)
                    {
                        notWanted.Add(eAvailableOperator);
                    }
                }

                notWanted.ForEach(f => e.AvailableOperators.Remove(f));
                e.DefaultOperator1 = FilterOperator.Contains;
            }
        }


Dimitar
Telerik team
commented on 10 Nov 2023, 07:59 AM

Hi Ohad, 

I tested your approach with the sample app (used the Name column) and it works. I have attached a screenshot that shows this. 

Let me know what I am missing.

Tags
GridView
Asked by
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Dimitar
Telerik team
Ohad
Top achievements
Rank 3
Bronze
Iron
Iron
Share this question
or