Sort in tabulator

844 views Asked by At

I have a problem with tabulator sort, when I use a one column formatter, and I multiply the value.

Sorting takes the initial value and not the value resulting from the multiplication, so the sorter is wrong.

formatter: function(cell, formatterParams) {
                                        var value = cell.getValue();
                                        if (cell.getRow().getData().Tipo == 'Holfuy') {
                                            value=cell.getValue()*5;
                                            return value;
                                        } else {
                                            return value;
                                        }
                                    },

enter image description here

Thanks for the help.

1

There are 1 answers

2
Oli Folkerd On

This is happening because Tabulator formatters are visual only, they do not affect the underlying data used for sorting and filtering.

If you want the updated value to be included in the sort then you need to use a mutator not a formatter.

This will then convert the underlying data and will work when sorted:

mutator: function(value) {
    var value = value;
    if (data.Tipo == 'Holfuy') {
        return value * 5;
    } else {
        return value;
    }
},

Full details can be found in the Mutator Documentation