RactiveJS: How to sort table by computed value?

64 Views Asked by At

I'm new to ractive and looking at the table sort tutorial at https://ractive.js.org/tutorials/iterative-sections/#step-5

But what if I want to sort by a "computed" value, such as the output of:

{{#resources}}
    {{#if (type_id==1) }}
        {{name}}
    {{elseif parent_id!=15173}}
        {{name}}
    {{/if}}
{{/resources}}

or:

{{client.0.name}}

?

1

There are 1 best solutions below

0
Anatoli Radulov On

You can achieve this by using a sort() with a compare function argument - eg array.sort(function(a, b){ /* produce computed value for a and b (based on your template logic) and return a compare result for the new values});