title: AngularJS: Custom Sorting Function using OrderBy
body: <p>I am attempting to define my own sorting function using the documentation provided at <a href="http://docs.angularjs.org/api/ng.filter:orderBy" rel="nofollow">http://docs.angularjs.org/api/ng.filter:orderBy</a>.  </p>
  
  <p>Before I explain the code written, I will also mention the behaviour that I am expecting.<br>
  I have a table which contains a table header(th) and table data(td). When the user clicks on a column in the table (by column, I mean the th), the table data must sort based on the value in that column.  </p>
  
  <p>If the user clicks the same column again, then the sorting is changed to ascending / descending if the previous sorting criteria was descending / ascending respectively.<br>
  The user can sort using multiple columns. The first column selected is give the first priority. In case the first column value is the same, then the second column selected for sorting is used.  </p>
  
  <p>Now for the code. It can be found here: <a href="http://jsfiddle.net/xkjmv/" rel="nofollow">http://jsfiddle.net/xkjmv/</a>  </p>
  
  <p>Problem is that the <code>customSortFunction</code> returns the array as expected, but the sorting does not work - when the user clicks on the column header, the sorting should be either ascending or descending (basically toggle each time it is clicked).  </p>
  
  <p><strong>I want to return an array of string predicates since I will have multiple columns to sort, but a single column sort using string predicate itself is not working</strong></p>
  
  <p>EDIT: You can check the console to see the output that the custom sort function returns, if it is not obvious from the code.</p>