Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>var comparator = function(a, b) { var aName = a.get('name'), bName = b.get('name'), aParentId = a.get('parentId'), bParentId = b.get('parentId'); if(!aParentId || !bParentId || aParentId == bParentId) { // In these 3 cases, name has precedence if(aName &lt; bName) { return -1; } else if(aName &gt; bName) { return 1; } else { return 0; } } else if(aParentId &lt; bParentId) { return -1; } else /* aParentId &gt; bParentId */ { return 1; } }; </code></pre> <p>EDIT: Corrected. The two sorting levels have to be taken into account, keeping in mind that any missing parentId amounts to equal parentIds.</p> <p>You could also implement it as a list of fields / tailored comparators that execute one after the others, where the next comparator is delegated to when the current finds an equality.</p> <pre><code>var loopedComparator = function(a, b) { var fields = [ { name: 'parentId', comparator: function(a, b) { return (!a || !b || a == b) ? 0 : (a &lt; b) ? -1 : 1; } }, { name: 'name', comparator: function(a, b) { return (a == b) ? 0 : (a &lt; b) ? -1 : 1; } } ]; var i, result = 0; for(i in fields) { var field = fields[i]; result = field.comparator(a.get(field.name), b.get(field.name)); if(result !== 0) { return result; // On inequality we return right away } // Else we continue, delegating the comparison to the next field / comparator } // When the loop is done, or if fields was defined empty, we return the last equality return result; }; </code></pre> <p>Of course with this scheme you can add as many columns as you like and define custom comparators for each of them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload