Search code examples
javascriptobjectparenttabulartabulator

Tabulator: editing nested value and getting parent object


Im trying to get the parent object of a nested field that I'm editing.

Lets assume my column definition is like this:

columns:[
        {title:"Name" + i, field:"user" + i + ".name", cellEdited : cellEditDone},  
    ],

And my cellEditDone looks like this:

cellEditDone: function (cell) {
  var rowData = cell.getRow().getData();

  var value = cell.getValue();
}

Now as you can see the column definitions(s) may be dynamically generated based on how many manes should appear in a row.

So, when I finish editing the cell, I need to get the specific object (in this case the user object) that has been edited, and not just the name field.

Can I somehow get the parent of the cells field or can I somehow get additional custom data to the cellEditDone function for each row/cell as to identify the specific user having the name edited?


Solution

  • Well. Been at it for the whole evening and 5 minutes after I post a question here, I find a solution..

    It turns out that you can add custom data to the column definition;

    columns:[
            {title:"Name" + i, field:"user" + i + ".name", cellEdited : cellEditDone, userIndex : i},  
    ],
    

    and retrieve it like this in the editDone event :

    var definition = cell.getColumn().getDefinition();
    var theIndex = definition.userIndex;