英文:
Tabulator.js Using Icon Column as Row header
问题
我刚开始使用tabulator.js。我创建了一个表格,其中第一列是一个图标列,当高亮显示一行时,应该显示一个右箭头。也就是说,我想要做的是只在高亮显示的行上显示箭头,使用rowMouseEnter(显示箭头)和rowMouseLeave(隐藏箭头),如图片所示。
代码:
$(function(){
table.on("rowMouseEnter", function(e, row){
// 这里是显示行的第一个单元格中的箭头的代码。
});
table.on("rowMouseLeave", function(e, row){
// 这里是清除行的第一个单元格中的代码。
});
});
var table = new Tabulator("#table", {
data: dataTable,
layout:"fitColumns",
addRowPos: "bottom",
tabEndNewRow: true,
columns:[
{headerSort:false, frozen:true, width:30, minWidth:30},
{title:"Name", field:"name"},
{title:"Progress", field:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Rating", field:"rating"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob"}
]
});
英文:
I just started using tabulator.js. I've created a table with the first column as an icon column that should show a right arrow when a row is highlighted. That is, what I want to do is show the arrow only on the highlighted row using rowMouseEnter (show arrow) and rowMouseLeave (hide arrow) as shown in the picture.
Code:
$(function(){
table.on("rowMouseEnter", function(e, row){
// Here code to show arrow in the first cell of the row.
});
table.on("rowMouseLeave", function(e, row){
// Here code clear the first cell of the row.
});
});
var table = new Tabulator("#table", {
data: dataTable,
layout:"fitColumns",
addRowPos: "bottom",
tabEndNewRow: true,
columns:[
{headerSort:false, frozen:true, width:30, minWidth:30},
{title:"Name", field:"name"},
{title:"Progress", field:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Rating", field:"rating"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob"}
]
});
答案1
得分: 2
我看到你在我输入时已发布了你自己的答案 很高兴你找到了答案!我会将我的看法作为另一种选择留在这里:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const data = [
{ id: 1, name: 'Billy Bob', age: '12', gender: 'male', height: 1, col: 'red', dob: '', cheese: 1 },
{ id: 2, name: 'Mary May', age: '1', gender: 'female', height: 2, col: 'blue', dob: '14/05/1982', cheese: true },
{ id: 10, name: 'Margret Marmajuke', age: '16', gender: 'female', height: 5, col: 'yellow', dob: '31/01/1999' }
]
const table = new Tabulator('#example-table', {
data: data,
selectable: true,
columns: [
{ headerSort:false, frozen:true, width:30, minWidth:30},
{ title: 'Name', field: 'name' },
{ title: 'Age', field: 'age' },
{ title: 'Gender', field: 'gender' },
{ title: 'Height', field: 'height' },
{ title: 'Favourite Color', field: 'col' }
]
})
function rowArrow(row, arrow) {
let cells = row.getCells()
let el = cells[0].getElement()
el.innerHTML = arrow ? '<div class="arrow-right"></div>' : ''
}
table.on("rowMouseEnter", (e, row) => rowArrow(row, true))
table.on("rowMouseLeave", (e, row) => rowArrow(row, false))
<!-- language: lang-css -->
.arrow-right {
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid #333;
margin: 3px auto;
}
<!-- language: lang-html -->
<link href="https://unpkg.com/tabulator-tables@5.5.0/dist/css/tabulator.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.5.0/dist/js/tabulator.min.js"></script>
<div id="example-table"></div>
<!-- end snippet -->
请注意,这是您提供的原始代码,没有进行任何翻译。
英文:
I see you posted your own answer while I was typing Glad you found the answer! I will leave my take on it here as an alternative:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const data = [
{ id: 1, name: 'Billy Bob', age: '12', gender: 'male', height: 1, col: 'red', dob: '', cheese: 1 },
{ id: 2, name: 'Mary May', age: '1', gender: 'female', height: 2, col: 'blue', dob: '14/05/1982', cheese: true },
{ id: 10, name: 'Margret Marmajuke', age: '16', gender: 'female', height: 5, col: 'yellow', dob: '31/01/1999' }
]
const table = new Tabulator('#example-table', {
data: data,
selectable: true,
columns: [
{ headerSort:false, frozen:true, width:30, minWidth:30},
{ title: 'Name', field: 'name' },
{ title: 'Age', field: 'age' },
{ title: 'Gender', field: 'gender' },
{ title: 'Height', field: 'height' },
{ title: 'Favourite Color', field: 'col' }
]
})
function rowArrow(row, arrow) {
let cells = row.getCells()
let el = cells[0].getElement()
el.innerHTML = arrow ? '<div class="arrow-right"></div>' : ''
}
table.on("rowMouseEnter", (e, row) => rowArrow(row, true))
table.on("rowMouseLeave", (e, row) => rowArrow(row, false))
<!-- language: lang-css -->
.arrow-right {
width: 0;
height: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid #333;
margin: 3px auto;
}
<!-- language: lang-html -->
<link href="https://unpkg.com/tabulator-tables@5.5.0/dist/css/tabulator.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.5.0/dist/js/tabulator.min.js"></script>
<div id="example-table"></div>
<!-- end snippet -->
答案2
得分: 0
已解决!!!
Tabulator.js文档非常棒。
以下是代码:
table.on("rowMouseEnter", function(e, row){
let cells = row.getCells();
let el = cells[0].getElement();
el.innerHTML = "<i class='material-icons'>arrow_right</i>";
});
table.on("rowMouseLeave", function(e, row){
let cells = row.getCells();
cells[0].setValue("");
});
英文:
Solved !!!
Tabulator.js documentation is great.
Here the code:
table.on("rowMouseEnter", function(e, row){
let cells = row.getCells();
let el = cells[0].getElement();
el.innerHTML = "<i class='material-icons'>arrow_right</i>";
});
table.on("rowMouseLeave", function(e, row){
let cells = row.getCells();
cells[0].setValue("");
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论