Search code examples
javascripthtmlcssbootstrap-4

Bootstrap Table Resizable Columns


I have found this documentation about resizable columns on bootstrap tables.

However i'm having a hard time understanding how to make a html table object to use this functionality. Could someone provide an example on how to use this?

I found this stackoverflow post about it but it was not what i was looking for since it uses split.js


Solution

  • Here's the official example from Bootstrap Table Examples:

    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.resizableColumns.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-table.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.resizableColumns.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bootstrap-table.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/extensions/resizable/bootstrap-table-resizable.min.js"></script>
    
    <table id="table"
      data-show-columns="true"
      data-search="true"
      data-show-toggle="true"
      data-pagination="true"
      data-url="json/data1.json"
      data-resizable="true">
      <thead>
        <tr>
          <th data-field="id" data-sortable="true">ID</th>
          <th data-field="name" data-sortable="true">Item Name</th>
          <th data-field="price" data-sortable="true">Item Price</th>
        </tr>
      </thead>
    </table>
    
    <script>
      $(function() {
        $('#table').bootstrapTable()
      })
    </script>