Tabulator 清楚地解释了这一点:http: //tabulator.info/examples/3.1
//Generate print icon
var printIcon = function(cell, formatterParams){ //plain text value
return "<i class='fa fa-print'></i>";
};
//Build Tabulator
$("#example-table").tabulator({
height:"311px",
fitColumns:true,
rowFormatter:function(row){
if(row.getData().col == "blue"){
row.getElement().css({"background-color":"#A6A6DF"});
}
},
columns:[
{formatter:"rownum", align:"center", width:40},
{formatter:printIcon, width:40, align:"center", cellClick:function(e, cell){alert("Printing row data for: " + cell.getRow().getData().name)}},
{title:"Name", field:"name", width:150, formatter:function(cell, formatterParams){
var value = cell.getValue();
if(value.indexOf("o") > 0){
return "<span style='color:red; font-weight:bold;'>" + value + "</span>";
}else{
return value;
}
}},
{title:"Progress", field:"progress", formatter:"progress", sorter:"number", width:100},
{title:"Rating", field:"rating", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
{title:"Driver", field:"car", align:"center", formatter:"tickCross", width:50},
{title:"Col", field:"col" ,formatter:"color", width:50},
{title:"Line Wraping", field:"lorem" ,formatter:"textarea"},
{formatter:"buttonCross", width:30, align:"center"}
],
});
这就是我通过将 window.location 触发到编辑页面来使用它的方式:
<script>
//Generate Edit icon
var editIcon = function(cell, formatterParams){ //plain text value
return "<i class='fas fa-pen-square'></i>";
};
//define data array
var tabledata = [
<?php echo $tableData; ?>
];
var table = new Tabulator("#example-table", {
data:tabledata, //load row data from array
layout:"fitColumns", //fit columns to width of table
responsiveLayout:"hide", //hide columns that dont fit on the table
tooltips:true, //show tool tips on cells
addRowPos:"top", //when adding a new row, add it to the top of the table
history:true, //allow undo and redo actions on the table
pagination:"local", //paginate the data
paginationSize:20, //allow XX rows per page of data
movableColumns:false, //allow column order to be changed ?
resizableRows:false, //allow row order to be changed ?
initialSort:[ //set the initial sort order of the data
{column:"name", dir:"asc"},
],
columns:[ //define the table columns
{title:"Department", field:"userDeptName", editor:false},
{title:"Description", field:"userDeptDesc", editor:false},
{formatter:editIcon, width:40, align:"center", cellClick:function(e, cell){
alert("Going To: " + cell.getRow().getData().userDeptName);
window.location = "/account-departments/"+ cell.getRow().getData().userDeptName;
}},
],
});
</script>