Tabulator: On row update, pass full set of data to the mutator

Created on 15 Feb 2019  路  4Comments  路  Source: olifolkerd/tabulator

Describe the bug
When I call row.update to update only a subset of data in a row, the mutators are called, but they are only passed the data that I am passing in the call to row.update rather than the data for the whole row.

In my mutator I refer to other data that I'm not changing. When the table is first created the mutator gets the full data for the row so this isn't a problem. The problem happens after I change the data with updateRow.

Tabulator Info

  • Which version of Tabulator are you using?
    4.2

To Reproduce

  1. Go to the above codepen. You can see that the data for Row 1, col 1 is mutated to "a2:a1" as col2 and col1 are concatenated.
    2 Click on the cell in r1c1
  2. The value changes to "undefined"
  3. In the console you can see that initially the mutator is passed the whole data for a row ,but after row.update({col1: "A1"}) is called, the mutator is only passed data { col1: "A1" } and so the mutator can't calculate the value.

Expected behavior
The mutator should change the value to "a2:A1"

Desktop (please complete the following information):

  • OS: [e.g. iOS]
    MacOS
  • Browser [e.g. chrome, safari]
    Chrome v64

Additional info
I do still have a hook to the original raw data that I use to pass into Tabulator. If I know which row is being mutated I could easily get the full row from the original data. In fact, the field that I was looking up in the data passed to the mutator was the index (ID) precisely for this reason. Therefore if it was possible to get the index in the mutator (e.g. by passing the row component so that I can call row.getIndex(), this would solve the issue. However, I can't see a way to get the index from the data passed to the mutator. Please let me know if I'm missing something.

In my local fork of Tabulator, I've actually implemented a different work around, by passing a "mutate" flag to row.update(), similar to the flag passed to cell.setValue(). I then mutate the data first (at that point I know which row I'm changing) and pass the processed data directly to row.update. This fix works for me. However, I think it may be a little specific to my case so it may not be the best solution for everyone.

Enhancement

Most helpful comment

Whenever I change a value by using another field of data in a mutator function, currently I do search on a whole data of table to get the data of another field which doesn't exist in the data object passed to the mutator function.
It's bit tricky. I'm looking forward to new version being released soon.
Thanks for your great product.

All 4 comments

Hey @gillez

Thanks for the info, as it happens i actually notice this one myself while i was coding for the 4.2 update. It is a hangover from a simple time before all row data was passed into mutators.

I will look at improving this on the 4.3 release.

Cheers

Oli :)

Thanks Oli. Keep up the good work.

Whenever I change a value by using another field of data in a mutator function, currently I do search on a whole data of table to get the data of another field which doesn't exist in the data object passed to the mutator function.
It's bit tricky. I'm looking forward to new version being released soon.
Thanks for your great product.

Hey @gillez

I have just pushed an update to the 4.5 branch which ensures the full updated row data object is passed into the mutator.

This should be released in the next few weeks

Cheers

Oli :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomheaps picture tomheaps  路  3Comments

tomvanlier picture tomvanlier  路  3Comments

c3pos-brother picture c3pos-brother  路  3Comments

yaxino picture yaxino  路  3Comments

iBek23 picture iBek23  路  3Comments