Megabit / Blazorise

Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Tailwind, Bulma, AntDesign, and Material.
https://blazorise.com/
Other
3.26k stars 529 forks source link

CustomSort #3816

Open joost00719 opened 2 years ago

joost00719 commented 2 years ago

Is your feature request related to a problem? Please describe. I am trying to order rows based on a value which is not defined in a field, but can be calculated with a method.

Describe the solution you'd like A clear and concise description of what you want to happen. Include any alternative solutions you've considered. I would like to see a method which takes in a TItem, and needs to return an int. This implementation should be very close to the System.IComparable interface With this solution you are able to render objects you cannot modify (e.g. because it is a nuget package, or in a separate DLL)

Additional context

Add any other context or screenshots about the feature request here. Implementing would look something like this image or image

which should be applied on the Blazorise.DataGrid.DataGridColumn

stsrki commented 2 years ago

You can do that with SortField parameter.

Example:

<DataGridColumn Field="Name" SortField="SomethingElse" />
joost00719 commented 2 years ago

But you cannot use a field of an object inside your class.

In my example I need to access Children.Count, this is not accessable. Besides that, it can be null and has an internal setter.

stsrki commented 2 years ago

I guess you can implement that same logic in the custom field getter.

public int SomethingElse => Children?.Count == 0;

If that doesn't work for you, we could consider adding something similar to what you propose.

joost00719 commented 2 years ago

That was my initial thought to use. However, the problem is that the list of objects I am trying to render, cannot be modified as it is from an internal nuget packages for our Domain Models.

I think adding a sort method to the component itself would be the best solution.

stsrki commented 2 years ago

Can you make a View model inherited from your domain model?

joost00719 commented 2 years ago

I'll try that. Thanks for the suggestion. Maybe keep this open to see if there's interest or not?

stsrki commented 2 years ago

Sure, it's not a bad idea to have.