fairly new to using tabulator but really love it for what I've seen so far. Unfortunately I´m stuck with the following problem: I want to calculate the sum of some of the cells in every row. Achieved this via using a mutator. Furthermore the mutator is also fired after the user edits a cell by the use of cellEdited with a function using row.update(). Everything is working fine until I add a formatter:"link" to one of the columns. Somehow the link-generation prevents the mutator from working. I think this has to do with the sequence of callbacks, but since I still know a little about tabulator and js thats just a guess.
Here is my (shortened) table-generator:
var table
var tabledata = table_data
var choices = [0, 1, 2, 3]
var getUrl = function(cell){
var url_id = cell.getRow().getCell('id').getValue();
return "/xyz/" + url_id
}
var customMutatorSumCur = function(value, data, type, params, component){
return data.knowledge + data.commitment;
}
table = new Tabulator(
"#ratings-table",
{
selectable:false,
layout:"fitDataTable",
data:tabledata,
columns:[
{title:"id", field:"id", visible:false},
{title:"Name", field:"name", formatter:"link", formatterParams:{
labelField:"name",
url:getUrl,
}},
{title:"Knowledge", field:"knowledge", editor:"select", editorParams:
{values:choices}, cellEdited:function(cell){
cell.getRow().update({points_cur:true})}},
{title:"Commitment", field:"commitment", editor:"select", editorParams:{values:choices}, cellEdited:function(cell){
cell.getRow().update({points_cur:true})},
{title:"Points", field:"points_cur", mutator:customMutatorSumCur},
],
);
The generated link is working fine, the value in the field "Points" is correct in the beginning, but its not updated on cell editing. If I omit this part:
, formatter:"link", formatterParams:{
labelField:"name",
url:getUrl,
the "Points" value is updated correctly after every cell-edit, but of course I no longer have a link. Maybe someone can point me in the right direction to where I made a mistake and can help me find a solution...
best regards, roman
A formatter will never prevent a mutator from running, they are completely separate systems, and the formatter is called any time a value in that cell has been updated.
The issue you are having is that the mutator is only called on a column when its value is updated, in this case your mutated column is getting its value from two other columns, so while those columns are updated the mutated value isnt because the mutator is not called again.
I would suggest calling the update function on the row in the cellEdited function on the name and knowledge columns, this will retrigger the mutator:
cell.getRow().update({"points_cur":true})
Also on a separate note, this line is a bit unnecessary, you do not need to retrieve the cell to get the data:
cell.getRow().getCell('id').getValue();
it should be:
cell.getData().id;