Completed
Last Updated: 21 Apr 2023 20:28 by Frank
Bert
Created on: 01 Feb 2022 20:30
Category: UI for Blazor
Type: Feature Request
0
Grid... Custom Sort Compare

Working with UI Blazor version 3.0.0

Setting a sort descriptor in the OnStateInitHandler.  

Everything works, but I need to customize the sort.  I need "A" and "a" to sort the same.  I also need blanks to sort at the bottom.  A custom sort method.  Can't figure out how to implement a SortCompare, can't find an example.

Here's what I have

                SortDescriptors = new List<SortDescriptor>()
                {
                    new SortDescriptor { Member = "lastname", 
                        SortDirection = ListSortDirection.Ascending,
                     SortCompare=CustomCompare  },
                    new SortDescriptor { Member = "lastname", SortDirection = ListSortDirection.Ascending }
                },
5 comments
Frank
Posted on: 21 Apr 2023 20:28

I don't think this question was properly answered. According to the documentation, SortCompare "Gets or sets the sort compare for this sort descriptor. Applicable only for jQuery based widgets such as US for ASP.NET MVC."

So first, would this even work with Blazor?

If so, how would that look like since there is no documentation about it?

If Bert does have a method called custom compare, how would that work?

private Telerik.DataSource.ClientHandlerDescriptor CustomComparator()
        {
            Telerik.DataSource.ClientHandlerDescriptor handlerDescriptor = new Telerik.DataSource.ClientHandlerDescriptor();
            handlerDescriptor.HandlerName = ???
            handlerDescriptor.TemplateDelegate = ???

            return handlerDescriptor;
        }

Would this in fact call a JavaScript function with the same name as the HandlerName? This doesn't seem to be working for me.

HandlerName is the name of the JavaScript function which will be called as a handler.

TemplateDelegate is a Razor template delegate. I'm not quite sure what that means exactly.

According to what I've read in the documentation SortCompare is not accessible from Blazor. So either your response or the documentation is not correct to an extent. Perhaps using the TemplateDelegate would allow for a custom sort logic? I'm not sure how to use that. Do you have any examples of this?

Thanks,

Frank

ADMIN
Hristian Stefanov
Posted on: 29 Jul 2022 15:13

Hi Alfonso,

I'm very sorry that it took me longer than expected to get back to you. Let me share the result of my talks with our development team.

Using the OnRead event to override the sorting is the most suitable approach in the situation here. The OnRead gives the current Grid SortDescriptors, and you can configure them on your own based on the app/scenario needs.

Still, I confirm that generalizing such custom functionality into a built-in feature/enhancement remains hardly feasible.

Thank you for that patience.

Regards,
Hristian Stefanov
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.

ADMIN
Hristian Stefanov
Posted on: 14 Jul 2022 19:01

Hi Alfonso,

Thank you for sharing your thoughts and feedback on the item.

Let me shed some light on the situation below.

This item is marked as completed because a Custom Sort Compare is achievable with the current Grid features and mainly custom logic that suits specific scenarios.

Different scenarios need different custom sort conditions. It is hardly possible to cover every scenario's requirements with a single built-in feature for Custom Sort Compare. There is always a need for custom coding because of the different sorting ways/options.

In case you use strings, I agree that to sort "1-2", "1-11" is hard. I will share your case with the development team and see if there is a possibility for a suitable approach or an enhancement. I will get back to you shortly here with more details.

Regards,
Hristian Stefanov
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.

Alfonso
Posted on: 07 Jul 2022 21:36

I don't think this answer, answers the question.  for example I have a string field, but I'd like to have it sort in a custom way, like:

"1-2" comes before
"1-11"  but as strings, it's the other way around.  I tried looking at the documentation and made the object implement IComparable, but that didn't seem to get used by the Grid at all.  Is that SortCompare implemented for Blazor?  if so, is there sample documentation about how to use it?

ADMIN
Hristian Stefanov
Posted on: 08 Feb 2022 13:58

Hi Bert,

The described functionality can be achieved with the current features Grid provide. It will require custom logic to sort the data.

The first way that comes to my mind is to define a property in the model in the role of a custom comparer. You can use this property to sort the data in the desired way.

Of course, there can be different ways for such custom sorting except for the above guidance. If you decide to try it on your own, take look at the Microsoft documentation for Sorting as well. The article contains more useful information.

Please keep me updated on the situation. Such a custom scenario example can turn out later on as a knowledge base article.

Regards,
Hristian Stefanov
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.