pstanoev / simple-svelte-autocomplete

Simple Autocomplete / typeahead component for Svelte
http://simple-svelte-autocomplete.surge.sh/
MIT License
464 stars 78 forks source link

Re-sorts my data #134

Closed mspanish closed 2 years ago

mspanish commented 2 years ago

I have an array of 2000+ objects, sorted alphabetically by one of the fields. When I load my data into your autocomplete, it re-sorts the data. Is there a way to preserve the original sort order on a large dataset, or specify a field to sort by? I see your 2 functions dedicated to sorting but need an example to see how to get them to work. I don't really need re-sorting I just want the script to preserve my data as it is.

I also have an index id in the data which could be used to sort by, it also disregards this.

mspanish commented 2 years ago

This was simple using the examples in your src folder, sorry I didn't look there first. The examples for sorting are here:

https://github.com/pstanoev/simple-svelte-autocomplete/blob/master/src/demo/CustomFunctionsExample.svelte

  function itemSort(item1, item2, keywords) {
    // sort by color order
    return item1.order - item2.order
  }
pstanoev commented 2 years ago

Added localSorting option to disable local sorting. Available in Version: 2.3.1