0

I am creating a react native app to load phone book contacts to my app using this library. I loaded contact correctly in my app. But contacts not in alphabetically order. Now I wanted to load contacts alphabetically order. How can I do that?

This is the error after adding sorting part.

Sidath
  • 379
  • 1
  • 9
  • 25

2 Answers2

1

Const tmpArray = _.sortBy(arrFinal, 'fullname')thanthis.setState({ contactList: tmpArray, isLoading: false })`

Rajan
  • 1,512
  • 2
  • 14
  • 18
0

You can modified library code. In Contacts.js file at line no 77, you will find getListOfContacts = () => {. Once you are done with change and you fill this feature should be in this library, Please raise PR for the same.

Rajan
  • 1,512
  • 2
  • 14
  • 18
  • What should I add as additional code? How to sort contacts? – Sidath Mar 30 '20 at 07:19
  • You can use lodash for sorting based on name. – Rajan Mar 30 '20 at 08:40
  • URL for lodash https://stackoverflow.com/questions/43371092/use-lodash-to-sort-array-of-object-by-value – Rajan Mar 30 '20 at 08:42
  • Thank you so much. I'll try this. – Sidath Mar 30 '20 at 09:05
  • If my answer correct. you please mark it as correct answer. – Rajan Mar 30 '20 at 09:22
  • I tried it. but nothing will happen. in my tab2.js i added `this.arrayholder = _.sortBy(arrFinal, 'fullname')`. but it not change anything else. – Sidath Mar 31 '20 at 03:57
  • @Sidath, you need to write it. In contact.Js file not in tab2.js. – Rajan Apr 01 '20 at 05:17
  • yeah, I right it in contact,js file. I copied that code into my tab2.js file. and after I added the above code. But nothing changed. – Sidath Apr 01 '20 at 05:38
  • You can check it here: (https://github.com/SidathDananjaya/Event-App/blob/master/Event-App/src/HomeTabs/tab2.js) – Sidath Apr 01 '20 at 05:43
  • I added ` _.sortBy(arrFinal, 'fullname')` before `this.setState({ contactList: arrFinal, isLoading: false }) `. But nothing changed. I messed up with this code. – Sidath Apr 01 '20 at 08:55
  • I added your code also. `arrFinal = _.sortBy(arrFinal, 'fullname') this.setState({ contactList: arrFinal, isLoading: false }) this.arrayholder = arrFinal` . But it show "arrFinal" is read-only. – Sidath Apr 01 '20 at 09:31
  • Here you can see the error. (https://i.stack.imgur.com/MeBrq.png) – Sidath Apr 02 '20 at 03:23