palantir-foundryfoundry-slate

Slate Functions Editor - 1 Table with 2 columns - Sort ASC


I has a table with 2 columns: id_pk and str_name_last_first How can I sort this table by name? if i use lower one.. the id-pk does not fit anymore to name.

var data = {{q_data}}
// data.str_name_last_first.sort();

return data

this example does not works:

employees.sort(function(a, b){
    var nameA=a.name.toLowerCase(), nameB=b.name.toLowerCase()
    if (nameA < nameB) //sort string ascending
        return -1 
    if (nameA > nameB)
        return 1
    return 0 //default return value (no sorting)
})

Solution

  • easy if you have the result :-)

    var data = {{f_data}}
    var data_rows = transformColumnSchemaToRowSchema(data);
    
    data_rows.sort((a, b) => {
        return a.str_team_name - b.str_team_name;
    });
    
    data_rows.sort((a, b) => {
        let fa = a.str_name.toLowerCase(),
            fb = b.str_name.toLowerCase();
    
        if (fa < fb) {
            return -1;
        }
        if (fa > fb) {
            return 1;
        }
        return 0;
    });
    
    return transformRowSchemaToColumnSchema(data_rows)