jquery - Tabulator table inside a JQuery UI dialog opens collapsed
问题描述
A Tabulator table put inside a JQuery UI Dialog opens collapsed (no rows visible). After clicking on a column header the table unrolls. Am I missing a setting?
This is for an ASP.Net web application, the table is defined as a within the dialog.
CustomerDataSet below is a JSON array of objects. The data mapping appears to work fine as the table opens after a click on a table heading.
var patTable = new Tabulator("#ptlist-table", {
selectable: 1,
data: CustomerDataSet,
columns: [
{ title: "Name", field: "name" },
{ title: "Customer ID", field: "id" },
{ title: "Location", field: "location" },
{ title: "Detail", field: "detail" },
{ title: "Order date/time", field: "timestamp" },
],
});
$("#dialog-id").dialog("open"); // The table shows inside the dialog.
I expect the table to show in full upon the dialog opening. Instead, the table shows collapsed until I click on a column heading.
解决方案
如果你初始化 Tabulator 的元素最初是隐藏的,你必须patTable.redraw(true)
在它显示后调用。这是因为当一个元素被隐藏时,JavaScript 返回 0 的宽度和高度。
因此,当 Tabulator 初始化时,它对其内部元素的宽度和高度所做的所有计算都将不正确,并且表格不会按预期呈现。如果您想研究这种情况,还有许多其他 JS 解决方法,但我建议只要求 Tabulator 重绘/重新渲染自身。
推荐阅读
- objective-c - 在 MacOS 上无法获得实际的 bssid 值
- python - 自定义解码字节数组
- c# - 如果 SyntaxNode 是一种方法并在当前 SyntaxTree 之外实现,如何获取它的内容?
- vim - Vim 找不到 Vundle 安装的颜色方案
- python - 如何将 virtualenv 复制到另一台没有相同解释器的机器上?
- php - 如何在 PHP 中只检查 JSON 中的根键?
- spring - 从子类中提取逻辑
- python - Python函数读取长度不起作用
- nunit - NUnit 自定义命令未调用 Execute()
- xml - xmlstarlet 不更新内容