繁体   English   中英

制表器表无法正确查看

[英]Tabulator table not view properly

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

单击按钮时,不显示任何内容在此处输入图片说明

当我按 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 中查看,查看这里

有人能告诉我为什么会这样吗?

这可能是因为您在隐藏表格时创建了表格。 Tabulator 在绘制时需要可见,因为 Virtual DOM 需要计算组成表格的元素的长度才能正确布局表格。 DOM 元素在第一次变得可见之前没有维度,这可能导致表中的某些损坏。

解决此问题的最简单方法是在表可见后立即在表上调用重绘函数。

table.redraw(true);

此主题在 Tabulator 网站上的快速入门指南中有详细介绍。

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

我猜table.redraw(true); 适用于制表符 4.0 及更高版本,如果您有较低版本的制表符,请使用table.redraw(); . 我也发生过这种情况,在升级到版本 4 之前我使用了tableRefernc.redraw()方法并且它运行良好,但是在升级到版本 4 后它运行不佳,所以我将其更改为tableRefernc.redraw(true)和它运作良好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM