npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Sorting table values with case insensitivity in react-data-sort

Hi,

I am using react-data-sort for table sort and pagination.I am unable to sort that data with case insensitivity.

The table list data in this format
A
B
C
a
b
c
Rather I want the sort to be in this format
A
a
B
b
C
c

Please let me know what changes has to be done

Thanks


How is this related to npm?


This board is for general JS discussion, so this topic is ontopic for it.


I changed that after he posted the comment


oh you moved it over here. Gotcha. Thanks! Maybe leave a note when you move it in the future to avoid confusion?


You might be better off asking there, on their issue tracker. There doesn’t seem to be a feature to do that at the moment. Below is a hint to point you to a way this could be done anyway, but no guarantees.

data
  .sort((a, b) => {
    // whatever comparison you want

    // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
    // for how to use this comparison

    // and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
    // for an example comparison that allows for alphabetical sorting
    // with more control
  })
  .forEach((object, index) => {
    // Assuming react-data-sort sorts with the default behaviour, which is comparing them as strings,
    // you have to prefix the numbers, as '10' would sort before '2' otherwise.
    let key = index.toString().padStart(data.length.toString().length, '0')
    object.key = key
  })

return (
  <DataSort
    data={data}
    defaultSortBy='key'
  />
)