Skip to content

Instantly share code, notes, and snippets.

@yozef
Created May 17, 2017 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yozef/7e3174e3087610686b6a11d8793dc7fc to your computer and use it in GitHub Desktop.
Save yozef/7e3174e3087610686b6a11d8793dc7fc to your computer and use it in GitHub Desktop.
TableView Indexes require an array of [{index: i, title: first_char_name}] this loop creates the rows + the index array
var indexArray = [];
var currentChar = '';
var lastChar = '';
// the Array e.places is already sorted alphabetically from ACS with order:'name' in query
for (var i = 0; i < e.places.length; i++) {
var farm = e.places[i];
// create an index of first chars of the farm name
currentChar = farm.name.charAt(0);
if (i == 0) indexArray.push({title: currentChar, index: i});
else {
if (lastChar != currentChar) indexArray.push({title: currentChar, index: i});
}
arrayForTableView.push({ title: farm.name, selectedBackgroundColor:'#50C45A' } );
lastChar = currentChar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment