tabalinas / jsgrid

Lightweight Grid jQuery Plugin
http://js-grid.com
MIT License
1.53k stars 353 forks source link

Adding natural sorting as a sorting strategy #1424

Open ClosedEyesSeeing opened 1 year ago

ClosedEyesSeeing commented 1 year ago

Using the 'numeric' and 'sensitivity' options in localCompare to provide a Natural Sort strategy.

This will keep the original intended sorting in place but provide an alternative for those that wish to use natural sorting for alphanumeric characters.

Example:

Normal string sort

  1. Item 1
  2. Item 10
  3. Item 2

Natural sort:

  1. Item 1
  2. Item 2
  3. Item 10

Usage is the same as any other sort strategy in jsGrid:

{ fields: [ ... { name: "Name", sorter: "stringNaturalSort" }, ... ] }