【问题标题】:Text wrapping on Tabulator制表符上的文本换行
【发布时间】:2021-04-01 11:33:39
【问题描述】:

var table = new Tabulator("#example-table", {
  layout: "fitColumns", //fit columns to width of table
  height: "69vh",
  responsiveLayout: "collapse", //hide columns that dont fit on the table
  cellVertAlign: "middle",
  headerSort: false,

  columns: [
    {
      title: "title",
      field: "title",
      width: 300,
      sorter: "string",
      formatter(cell, formatterParams) {
        return `<p class="p-name-inside-table" contenteditable="true">${cell.getValue()}</p>`;
      }
    },
    {
      title: "body",
      field: "body",
      sorter: "string",
      formatter(cell, formatterParams) {
        return `<p class="p-name-inside-table" contenteditable="true">${cell.getValue()}</p>`;
      }
    }
  ]
});

$.ajax({
  type: "GET",
  url: "https://jsonplaceholder.typicode.com/posts",
  success: function (data) {
    setTimeout(() => {
      table.addData(data, false);
      table.restoreRedraw();
    }, 200);
  }
});
body {
  font-family: Arial;
}

h1 {
  text-align: center;
  margin: 0, auto;
}

.button {
  justify-content: center;
  margin: 10px;
  text-align: center;
}

.button button {
  margin: 10px;
  padding: 10px;
}

.p-name-inside-table {
  width: 100%;
  cursor: default !important;
}

.p-name-inside-table img {
  cursor: pointer !important;
}
<link href="https://unpkg.com/tabulator-tables@4.9.3/dist/css/tabulator.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/tabulator-tables@4.9.3/dist/js/tabulator.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<h1>Tabulator</h1>

<div id="example-table"></div>

如何换行标题的行,使其不会在制表符上被截断?您可以看到行被截断,我在文档中找不到 (http://tabulator.info)

( ----这是为了避免“大部分是代码”错误-------------------------------- --------------------------------------------------)

【问题讨论】:

    标签: javascript tabulator


    【解决方案1】:

    一点点 CSS 就可以解决问题:

    .tabulator .tabulator-header .tabulator-col .tabulator-col-content .tabulator-col-title {
        white-space: normal !important;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 2022-01-25
      • 2022-09-23
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多