<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: SAPUI5 sort table column with custom comparator in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sapui5-sort-table-column-with-custom-comparator/qaa-p/750986#M213570</link>
    <description>&lt;P&gt;I forgot to set the operationMode to 'Client'. This solved my issue.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Dec 2018 21:27:31 GMT</pubDate>
    <dc:creator>former_member558862</dc:creator>
    <dc:date>2018-12-07T21:27:31Z</dc:date>
    <item>
      <title>SAPUI5 sort table column with custom comparator</title>
      <link>https://community.sap.com/t5/technology-q-a/sapui5-sort-table-column-with-custom-comparator/qaq-p/750985</link>
      <description>&lt;P&gt;I have a table column which displays customers full names (first name + last name). However, I want to sort this column first by first name and then by last name. Therefore I added some comparator function in my controller:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;_customNameComparator: function(value1, value2) {
    // Separate all words of the full name
    var aWordsName1 = value1.split(" ");
    var aWordsName2 = value2.split(" ");

    // Get the last and first names of the two names
    var sFirstName1 = value1.substring(0, value1.lastIndexOf(" "));
    var sLastName1 = aWordsName1[aWordsName1.length - 1];
    var sFirstName2 = value2.substring(0, value1.lastIndexOf(" "));
    var sLastName2 = aWordsName2[aWordsName2.length - 1];

    // 0 values are equal
    // -1 value1 smaller than value2
    // 1 value1 larger than value2

    if (sLastName1 === sLastName2) {
        if (sFirstName1 === sFirstName2) {
            return 0;
        } else if (sFirstName1 &amp;gt; sFirstName2) {
            return 1;
        } else {
            return -1;
        }
    } else if (sLastName1 &amp;gt; sLastName2) {
        return 1;
    } else {
        return -1;
    }
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Btw: I know that this can lead to some wrong sorting (e.g. for last names containing out of two or more words), but since it's "only" the sorting this is fine for me at the moment.&lt;/P&gt;
  &lt;P&gt;When the column Header is clicked, I try to call&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;var aSorter = [];
aSorter.push(new sap.ui.model.Sorter("FullName", bDescending, false, this._customNameComparator)); 
var oBinding = this.byId("tableTargetGroupDetails").getBinding("items");
oBinding.sort(aSorter);
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The comparator does not work like this. The sorting is just as usual (by the full name). What do I do wrong?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 17:01:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sapui5-sort-table-column-with-custom-comparator/qaq-p/750985</guid>
      <dc:creator>former_member558862</dc:creator>
      <dc:date>2018-12-07T17:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAPUI5 sort table column with custom comparator</title>
      <link>https://community.sap.com/t5/technology-q-a/sapui5-sort-table-column-with-custom-comparator/qaa-p/750986#M213570</link>
      <description>&lt;P&gt;I forgot to set the operationMode to 'Client'. This solved my issue.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Dec 2018 21:27:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sapui5-sort-table-column-with-custom-comparator/qaa-p/750986#M213570</guid>
      <dc:creator>former_member558862</dc:creator>
      <dc:date>2018-12-07T21:27:31Z</dc:date>
    </item>
  </channel>
</rss>

