javascriptdatabasesortingtaffydb

Taffy DB sorting my multiple columns


So, I am trying to sort a Taffy database on multiple columns, and getting unexpected results. This example:

<script src="./taffy/taffy.js"></script>
<script>

    var myTaffyDB = TAFFY([
        {"foo":"bar","letter":"A","number_01":48,"number_02":6},
        {"foo":"bar","letter":"S","number_01":49,"number_02":2},
        {"foo":"bar","letter":"Q","number_01":49,"number_02":3},
        {"foo":"bar","letter":"W","number_01":49,"number_02":4},
        {"foo":"bar","letter":"P","number_01":49,"number_02":5},
        {"foo":"bar","letter":"T","number_01":49,"number_02":6},
        {"foo":"bar","letter":"W","number_01":49,"number_02":7},
        {"foo":"bar","letter":"Q","number_01":49,"number_02":8},
        {"foo":"bar","letter":"A","number_01":49,"number_02":9},
        {"foo":"bar","letter":"C","number_01":49,"number_02":10},
        {"foo":"bar","letter":"B","number_01":50,"number_02":1}
    ]);
            var tempResultsArray = myTaffyDB({"foo":"bar"})
                .order("letter","number_01","number_02")
                .select( "letter", "number_01", "number_02")
            ;
        console.log( 'tempResultsArray: ' + tempResultsArray );

    </script>

Produces the following:

A,48,6,A,49,9,B,50,1,C,49,10,P,49,5,Q,49,8,Q,49,3,S,49,2,T,49,6,W,49,4,W,49,7

Note that the Q results are sorted in the order 49,8 then 49,3, despite the fact that the order call says group by letter, then number_01, then number_02.

Am I missing something in the way I am constructing this, or is there some limitation in the way Taffy orders results?


Solution

  • Try .order("letter, number_01, number_02").
    The source code said: // * Purpose: Accept filters such as "[col], [col2]" or "[col] desc" and sort on those columns.
    It worked for me.