Search code examples
tabulator

Tabulator: Have a value associated with cell


I am deciding to use this wonderful Tabulator js library but I want to have a different value associated with each cell value that is displayed.

Like

<td value="1">Bob</td>

I see the below options for setting a drop down

columns:[ 
        {title:"Name", field:"name", editor:"select", editorPramas: names
        ]

where names = { 1: 'Bob', 2: 'Jack'}

however this results in bob and Jack being displayed in the drop down and when Bob is selected it displays 1 in the cell value. However I want Jack and Bob to be in dropdown and when Bob is selected data cell gets value of 1 because I have columns values mapped to IDs which need to be stored in database.


Solution

  • This can be done by custom editorParams

    columns:[ 
            {title:"Name", field:"name", editor:"select", editorPramas: myCustom
            ]
    
    var myCustom = function(cell) {
        cell.getElement().setAttribute("value",2);
        ...
    }
    

    whereby one can get the cell element which is changed and accordingly change any attribute of it.