Search code examples
jqueryhtml-tabletabulator

In tabulator, how do you set cell level configuration for Select editor?


I have a select editor for one of my columns in tabulator table. However, I want to specifically disable the editor for one of my cells in the same column. Is there any configuration for it?

columns: [
              { title: "name", field: "name" },
              { title: "date", field: "gender" },
              {title: "gender", editor: "select", editorParams: {
                        values: gender
                         }
               }]

Solution

  • If you are specifically wanting to block the edit under circumstances then you can pass a callback to the editable function that should return true when a cell is editable and false when a cell is not

    var editCheck = function(cell){
        //cell - the cell component for the editable cell
    
        //get row data
        var data = cell.getRow().getData();
    
        return data.age > 18; // only allow the name cell to be edited if the age is over 18
    }
    
    //in your column definition for the column
    {title:"Name", field:"name", editor:"input", editable:editCheck}
    

    If you more specifically want to change the params passed into the editor per cell, then you can pass a function to the editorParams column definition property that should return the params object, this function is called just before the editor is created

    //define lookup function
    function paramLookup(cell){
        //cell - the cell component
    
        //do some processing and return the param object
        return {param1:"green"};
    }
    
    //column definition
    {title:"Rating", field:"rating", editor:"star", editorParams:paramLookup}
    

    Details on all edit functionality can be found in the Editing Documentation