Search code examples
javascripttabulator

How to get row Index from cellEdited:function(cell)? - Tabulator


I have a typical tabulator setup with keybindings:{"navUp" :"38","navDown" :"40","navLeft" :"37","navRight" :"39"} enabled.

When edit a cell it updates data successfully and moves programmatic in the next cell bellow

    cellEdited:function(cell){
            
         let updateValue = updateValueQuery(columnIndex,rowIndex,cell.getValue()).then(function(done){
         cell.nav().down();
         });
    }

When in a new cell down, the rowId doesn't change (its behavior is not like rowClick)

What i'm trying to figure out is: How to get row.getIndex(); inside of cellEdited:function(cell){}

    cellEdited:function(cell){

         // ->> How i can obtain rowIndex = row.getIndex(); here or if there is another more optimal way.

         let updateValue = updateValueQuery(columnIndex,rowIndex,cell.getValue()).then(function(done){
         cell.nav().down();
         });
    }

I've tried to put row attribute in cellEdited:function(cell,row) but without luck.

Any help will be appreciated! thank you for your time!


Solution

  • I'm not sure I understand your question but you can access the row through the cell component methods

    var row = cell.getRow();
    

    And you can also just get the data without going through the row:

    Get Data

    The getData function returns the data for the row that contains the cell.

    var dataID = cell.getData().id; 
    // the name of the property you are using for the index
    

    Or use getIndex

    Get Index

    The getIndex function returns the index value for the row. (this is the value from the defined index column, NOT the row's position in the table)

    var rowIndex = row.getIndex();
    

    If you want to get the next or previous logical row, you can use the methods of the row component:

    Get Next Row

    The getNextRow function returns the Row Component for the next visible row in the table, if there is no next row it will return a value of false.

    var nextRow = row.getNextRow();
    var prevRow = row.getPrevRow();
    

    And finally:

    Get Position

    Use the getPosition function to retrieve the numerical position of a row in the table. By default this will return the position of the row in all data, including data currently filtered out of the table.

    If you want to get the position of the row in the currently filtered/sorted data, you can pass a value of true to the optional first argument of the function.

    var rowPosition = row.getPosition(true); 
    //return the position of the row in the filtered/sorted data