javascript - 制表符表无法正确查看

标签 javascript jquery html tabulator

我有一个按钮,当单击按钮时将显示表格(制表符),但问题是当单击按钮时,表格未正确显示,表格是 View 但内容未显示,我需要触发操作,如调整窗口大小或按 F12 显示内容。

点击按钮时,不显示任何内容 enter image description here

当我按 F12 时,内容 View 但标题丢失(红线) enter image description here

当我尝试在 jsfiddle 中进行测试时,标题显示但内容不显示(需要调整窗口大小以显示数据) enter image description here

我尝试的是这样的:

$(document).on('click', '#testing', function(){
	$('#example-table').show();
});

//define some sample data
 var tabledata = [
 	{id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
 	{id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
 	{id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
 	{id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
 	{id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
 ];
 
 //create Tabulator on DOM element with id "example-table"
var table = new Tabulator("#example-table", {
 	height:205, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
 	data:tabledata, //assign data to table
 	layout:"fitColumns", //fit columns to width of table (optional)
 	columns:[ //Define Table Columns
	 	{title:"Name", field:"name", width:150},
	 	{title:"Age", field:"age", align:"left", formatter:"progress"},
	 	{title:"Favourite Color", field:"col"},
	 	{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
 	],
 	rowClick:function(e, row){ //trigger an alert message when the row is clicked
 		alert("Row " + row.getData().id + " Clicked!!!!");
 	},
});
<link href="https://unpkg.com/tabulator-tables@4.1.4/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@4.1.4/dist/js/tabulator.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<button id='testing'>Click this button !!</button>
<div id="example-table" style='display:none'></div>

你也可以检查 jsfiddle,检查 here

谁能告诉我为什么会这样?

最佳答案

这可能是因为您在隐藏表格时创建表格。 Tabulator 在绘制时需要可见,因为 Virtual DOM 需要计算组成表格的元素的长度以正确布局表格。 DOM 元素在首次显示之前没有维度,这可能会导致表格中出现一些损坏。

最简单的方法是在表格可见后立即调用表格的重绘函数。

table.redraw(true);

此主题在 Quickstart Guide 中有详细介绍在 Tabulator 网站上。

它不会在 Chrome 中发生的原因是因为 chrome 实现了 ES8 ResizeObserver 功能,制表符可以使用它来确定表格何时改变形状或变得可见。此功能在其他浏览器中尚不可用。

关于javascript - 制表符表无法正确查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139731/

相关文章:

javascript - 在 Facebook 上分享链接时出现 404 页面未找到错误

html - Safari Mobile Multi-Line <Select> aka GWT Multi-Line ListBox

javascript - 类与函数返回对象

javascript - HTML5 拖放上传在 IE 10 版本以下不起作用

javascript - jQuery show() 在 hide() 之后不起作用

javascript - 为什么我的弹出窗口不关闭?

jquery - 如何将 After Effects 动画嵌入我的网站?

javascript - 更新的表标题附加到前一个,而不是替换它

javascript - 错误 : while using devtool ="source-map" option in webpack config version 5

javascript - 在 jquery 中点击后退按钮后,删除的内容被替换回来