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

Custom filtering and sorting for a dependent column in the grid

4 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 14 Oct 2019, 08:42 AM

Have a dependent grid column that is a dropdown based on a parent column.

The dependent field is filtered on its accepted values on the popup editor based on the selection on the parent column.

But on the grid, I am just showing the current value, like so:

columns.Bound(o => o.CountyId).ClientTemplate("#if(CountyId.Value!=null){##=CountyId.Value##}#").Sortable(false).Groupable(false).Filterable(false);

[UIHint("CountyEditor")]
[Display(Name = "County")]
public ChildValueViewModelNullable CountyId { get; set; }

 

Would like to enable filtering "AND" sorting on this column.  Would be happy with just a text field where users can enter in the search term for the filtering.

Do you have code/sample for this?

Thnks.

4 Answers, 1 is accepted

Sort by
0
Edward
Top achievements
Rank 1
answered on 15 Oct 2019, 09:03 PM

Sorting is resolved... by implementing IComparable for underlying data model.

As for filtering, tried:

 

columns.Bound(o => o.CountyId).ClientTemplate("#if(CountyId.Value!=null){##=CountyId.Value##}#").Filterable(filterable => filterable
                                                           .Extra(false)
                                                           .Operators(operators => operators
                                                                .ForString(str => str.Clear()
                                                                .StartsWith("Contains")
                                                                .IsEqualTo("Is equal to")
                                                                .IsNotEqualTo("Is not equal to")
                                                                )));

This gives a textbox for the search field, but the operators dropdown is not populated.

0
Viktor Tachev
Telerik team
answered on 17 Oct 2019, 07:27 AM

Hi Edward,

 

The example linked below illustrates how you can have filtering and sorting enabled for a column that is bound to an object.

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/enable-operations-for-object-column

Give the approach a try and let me know how it works for you.

 

Regards,
Viktor Tachev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Edward
Top achievements
Rank 1
answered on 18 Oct 2019, 10:03 AM

Thanks I will look into it.

There is further issue with the sorting however.  I solved it partially by implementing IComparable for the bound object.  However the issue is the object is originally IEnumerable<T>.  When it was IEnumerable<T> it was working properly (except for the sorting/filtering).

By implementing something like:

EnumerableOfT: IEnumerable<T>, IComparable

for the bound object for the column/field, sorting worked.

However, the binding of the object on web api controller calls are not working on the post side.

For e.g. for:

[HttpPost]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<MainViewModel> models)

the bound column is always null.

On the read side, the binding works however, when retrieving data the column is properly bound.  Only on updates/creates the binding seems to fail... 

0
Viktor Tachev
Telerik team
answered on 23 Oct 2019, 07:25 AM

Hi Edward,

 

The behavior you describe seems rather strange. Would you send us a runnable sample where it is replicated? Or modify the sample from my previous post and send it back? This will enable us to examine the issue locally and look for its cause.

 

Regards,
Viktor Tachev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Edward
Top achievements
Rank 1
Answers by
Edward
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or