首页 > 解决方案 > 如果我在 javascript 中设置列​​,则引导表调整列大小不起作用

问题描述

我正在使用以下示例来做可调整大小的列:

https://live.bootstrap-table.com/example/extensions/resizable.html

如果我按照链接示例进行操作,请在以下位置设置列thead

<table id="table"

  data-url="json/data1.json"
  data-resizable="true">
  <thead>
    <tr>
      <th data-field="id" data-width="18">ID</th>
      <th data-field="name" data-width="20">Item Name</th>
      <th data-field="price" data-width="25">Item Price</th>
    </tr>
  </thead>
</table>

<script>
  $(function() {
    $('#table').bootstrapTable()
  })

然后我可以调整列的大小。

但是,如果我在 js 中设置列​​,例如:

<table id="table"

  data-url="json/data1.json"
  data-resizable="true">

</table>

<script>
  var defaultColumns = [        
        {title: 'Id', field: 'id', width: 180},
        {title: 'Name', field: 'name', width: 100},
        {title: 'Price', field: 'price', width: 180}            
        ];

  $(document).ready(function() {

    $( '#table' ).bootstrapTable(

        {columns: defaultColumns}
    );
  });

然后我无法调整列的大小。

如果我在js中设置列,如何调整列的大小?

标签: jquerybootstrap-4bootstrap-table

解决方案



推荐阅读