olifolkerd / tabulator

Interactive Tables and Data Grids for JavaScript
http://tabulator.info
MIT License
6.71k stars 818 forks source link

setdata with click in cell #389

Closed ramonrt closed 7 years ago

ramonrt commented 7 years ago

Hi, i have 2 tables, I want when click in a cell of first table, setdata of second table.

rowDblClick:function(e,row){var cellValue = row.getCell("id").getValue(); alert(cellValue); $("#table-2").tabulator("setData","http://www.getmydata.com/now", {key1:cellValue),}, "POST");}

only work with a button $("#button").click(function(){ $("#table-2").tabulator("setData","http://www.getmydata.com/now", {key1:cellValue),}, "POST");}` });

Thanks for the support and great work!

olifolkerd commented 7 years ago

Hey,

You have to use the cellClick callback in the column definition array to detect a click on cells. because Tabulator uses a virtual dom you cannot use jQuery to bind to the cells as they are created and destroyed as you scroll:


var cellClickHandler = function(e, cell){
    //e - the click event object
    //cell - cell component

    $("#table-2").tabulator("setData","http://www.getmydata.com/now", {key1:cell.getValue()),}, "POST");}`
}

$("#example-table").tabulator({
    columns:[
        {title:"Name", field:"name", cellClick:cellClickHandler }
    ]
});

Let me know if that helps

Cheers

Oli

ramonrt commented 7 years ago

thank you for the quick reply, work perfect