tinybase icon indicating copy to clipboard operation
tinybase copied to clipboard

Allow custom sorter function for getSortedRowIds

Open brandonzylstra opened this issue 1 year ago • 4 comments

Describe the bug

  1. Navigate to https://codepen.io/pen?editors=0110
  2. Click on the "id" column until it is sorted in ascending order
  3. Notice that it is not a numeric sort

Your Example Website or App

https://codepen.io/pen?editors=0110

Steps to Reproduce the Bug or Issue

  1. Navigate to https://codepen.io/pen?editors=0110
  2. Click on the "id" column until it is sorted in ascending order
  3. Notice that it is not a numeric sort

Expected behavior

Integers should be sorted as integers.

Screenshots or Videos

image

Platform

  • OS: macOS
  • Browser: Sidekick (Chrome)
  • Version: 124.61.1.50292 (Official Build) (arm64)

Additional context

No response

brandonzylstra avatar Oct 23 '24 00:10 brandonzylstra

@brandondrew I couldn't load your codepen and I have confirmed that I can load other codepens. Your link just shows a blank environment. (Maybe you have to publish it.)

waynesbrain avatar Oct 24 '24 23:10 waynesbrain

It's this demo: https://tinybase.org/demos/ui-components/sortedtableinhtmltable (and I think @brandondrew launched it into CodePen).

Ids everywhere in TinyBase are strings so this is the correct ordering. Where numbers have been used for them (as in the case of the movie demo) it does look weird.

One API improvement this suggests is to add a custom sorter function to the getSortedRowIds method so that the default sort can be overridden. Changing issue title accordingly!

jamesgpearce avatar Oct 27 '24 11:10 jamesgpearce

Okay, sorry if this is a dumb questions, but is there a reason for IDs to be strings?

brandonzylstra avatar Oct 28 '24 00:10 brandonzylstra

Well that's not a stupid question! It has just been an 'opinion' used in the design of TinyBase, and to ensure that there isn't confusion between types. (You can have a string representation of a number, but not a number representation of a string)

jamesgpearce avatar Nov 03 '24 23:11 jamesgpearce