【发布时间】:2019-01-11 02:51:25
【问题描述】:
我有一个按钮,单击按钮时将显示表格(制表符),但问题是单击按钮时,表格无法正确显示,表格是视图但内容未显示,我需要触发操作,例如调整窗口大小或按 F12 显示内容。
当我尝试在 jsfiddle 中测试时,显示标题但内容不显示(需要调整窗口大小以显示数据)
我尝试的是这样的:
$(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
谁能告诉我为什么会这样?
【问题讨论】:
-
JSfiddle 和 SO 代码 sn-p 似乎在这里按预期工作。
-
@visibleman 先生,您使用什么浏览器?我检查了 mozilla 和 google chrome 仍然有这个问题。
-
Windows 上的 Google Chrome 版本 71.0.3578.98(官方构建)(64 位)
-
我在 chrome 和 opera 中看到它正确,我在 firefox 和 edge 看到你的问题,所以似乎与浏览器相关
-
想想它在 html 中设置 display 为 none 的部分
标签: javascript jquery html tabulator