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

DataGrid Sorting on ProtoBuf.WellKnownType.TimeStamp not working as expected #909

Closed CDarbonne closed 3 years ago

CDarbonne commented 4 years ago

Describe the bug

When using the automatic sort in the DataGrid on a column containing a ProtoBuf.WellKnownType.TimeStamp, an exception occurs stating that at least one item must implement IComparable. I have confirmed that TimeStamp does, in fact, implement IComparable both through checking their GitHub and also through my own testing, just to be doubly sure.

I have also tried using the DataGridDateColumn as well, just to cover my bases, despite it stating it is for a DateTime type field and that did nothing to help, as expected.

I am of course open to the possibility that this is user error on my part, but it seems as though there is something not working quite right.

To Reproduce Steps to reproduce the behavior:

  1. Create a DataGrid.
  2. Add a DataGridColumn with a ProtoBuf.WellKnownType.TimeStamp property as the Field and set Sortable="true".
  3. Attempt to auto sort column by clicking on the column header.
  4. See error

Expected behavior

I expect the column to be ordered by date.

Example Code

<DataGrid TItem="Item"
          Data="@Items"
          ShowPager="true"
          PageSize="50"
          RowSelectable=@((item)=>false)>
    <DataGridColumn TItem="Item" Field="@nameof(Item.LastModified)" Caption="Modified" Sortable="true" />
</DataGrid>

Stack Trace

blazor.server.js:15 [2020-05-20T14:28:31.711Z] Error: System.InvalidOperationException: Failed to compare two elements in the array.
 ---> System.ArgumentException: At least one object must implement IComparable.
   at System.Collections.Comparer.Compare(Object a, Object b)
   at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
   at System.Linq.EnumerableSorter`2.CompareAnyKeys(Int32 index1, Int32 index2)
   at System.Collections.Generic.ArraySortHelper`1.SwapIfGreater(T[] keys, Comparison`1 comparer, Int32 a, Int32 b)
   at System.Collections.Generic.ArraySortHelper`1.PickPivotAndPartition(T[] keys, Int32 lo, Int32 hi, Comparison`1 comparer)
   at System.Collections.Generic.ArraySortHelper`1.IntroSort(T[] keys, Int32 lo, Int32 hi, Int32 depthLimit, Comparison`1 comparer)
   at System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
   --- End of inner exception stack trace ---
   at System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer)
   at System.Array.Sort[T](T[] array, Int32 index, Int32 length, IComparer`1 comparer)
   at System.Linq.EnumerableSorter`2.QuickSort(Int32[] keys, Int32 lo, Int32 hi)
   at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
   at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Blazorise.DataGrid.DataGrid`1.FilterData(IQueryable`1 query)
   at Blazorise.DataGrid.DataGrid`1.FilterData()
   at Blazorise.DataGrid.DataGrid`1.get_LastPage()
   at Blazorise.DataGrid.DataGrid`1.get_LastVisiblePage()
   at Blazorise.DataGrid.DataGrid`1.<BuildRenderTree>b__289_3(RenderTreeBuilder __builder3)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at Blazorise.Pagination.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
CDarbonne commented 4 years ago

Not trying to rush you if you plan to look into this, but I notice this board is very active and this issue is one of the only ones not even acknowledged in any way. If this is something you don't plan to deal with, please let me know so that I can seek other solutions.

I can understand that you are busy with an active repo and appreciate any time you can give, even if it is just to let me know nothing can be done. Thanks in advance. :)

stsrki commented 4 years ago

@CDarbonne I'm sorry for not answering before. Sometimes there are so many emails coming when I'm out that I tend to overlook some of them. Be sure that every ticket will eventually be looked upon. But since I'm just one guy working on this in my spare time, it can take time. Especially considering some work issues lately...

Back to your problem. To tell you the truth I'm not familiar with ProtoBuf types. Quick googling show me that it's something about special data types and/or network protocols. Correct me if I'm wrong. I will need to investigate more it seems.

So, if you got time to look at this by yourself that would be the fastest route I think. v0.9.1 is near finish and I don't want to prolong it any more. v.0.9.2 would be soonest I can start looking on it, unless someone picks it up before.

CDarbonne commented 4 years ago

No worries, I understand completely.

Yes, you are correct. It is a protocol gaining popularity that requires a few special types to replace a few more standard ones.

Unfortunately, I am building a product on a deadline and won't have time to look into it myself until downtime between projects. For now, I will find a workaround to complete the current solution. That being said, if it has not been picked up by then I will most certainly pick back up and see if I can't figure out the issue. I'm very impressed by this repo and would love to give back a bit when I have the time.

Thanks for your response!