Bootstrap Table

repository·develop·Indexed 11 days ago

https://github.com/wenzhixin/bootstrap-table

An extended table plugin for Bootstrap and other CSS frameworks (Semantic UI, Bulma, Material Design, Foundation). Version 1.27.3 provides advanced features including AJAX data loading, row selection, pagination, responsive design, and full configurability via data attributes.

Tokens
51K
Snippets
175
Records
246
Agent score
95%

What's inside Bootstrap Table

  1. Overview of Bootstrap Table features

    develop

    Bootstrap Table is an extended Bootstrap table plugin designed for Twitter Bootstrap (all versions supported). Key features include:

    • Responsive Design: Supports responsive web layouts.
    • Layout Control: Scrollable tables with fixed headers, and the ability to show/hide columns, headers, or footers.
    • Data Handling: Get data in JSON format using AJAX and simple column sorting via click.
    • Selection & View Modes: Single or multiple row selection, Card view, and Detail view.
    • Advanced UI: Powerful pagination, column formatting, and localization.
    • Extensibility: Fully configurable via data attributes and supports various extensions.
  2. Supported browsers and devices for Bootstrap Table

    develop

    Bootstrap Table focuses on the latest, stable releases of all major browsers and platforms, prioritizing modern browsers with high performance and security.

    While alternative browsers using WebKit, Blink, or Gecko (including platform web view APIs) are not explicitly supported, Bootstrap Table should function correctly in most cases. Compatibility is designed to be consistent with Bootstrap's own browser and device support requirements.

  3. Bootstrap Table License Terms

    develop

    Bootstrap Table is released under the MIT license.

    Requirements

    • You must keep the license and copyright notice included in Bootstrap Table's CSS and JavaScript files when using them in your works.

    Permissions

    • Usage: Freely download and use Bootstrap Table (in whole or in part) for personal, private, company internal, or commercial purposes.
    • Distribution: Use Bootstrap Table in packages or distributions you create.
    • Modification: Modify the source code.
    • Sublicensing: Grant a sublicense to modify and distribute Bootstrap Table to third parties.

    Restrictions

    • Liability: You cannot hold the authors, license owners, or copyright holders liable for damages; the software is provided without warranty.
    • Attribution: Do not redistribute any piece of Bootstrap Table without proper attribution.
    • Endorsement: Do not use marks owned by Zhixin Wen in any way that implies endorsement of your distribution or implies that you created the software.

    Non-Requirements

    • You are not required to include the source code of Bootstrap Table or your modifications in your redistribution.
    • You are not required to submit your modifications back to the Bootstrap Table project.
  4. What is the Table Pipeline extension?

    develop

    The Table Pipeline extension enables client-side data caching for server-side requests. It provides a performance balance for large datasets by allowing the table to fetch data in 'cache windows' rather than making a new server request for every single page change.

    How it works:

    1. The extension divides the total dataset into windows based on the pipelineSize.
    2. When a user changes pages, the extension checks if the new offset falls within the current cached window.
    3. If it does, the data is served from the local cache (a 'cache hit').
    4. If it does not, a new server-side request is issued for the next window (a 'cache reset').

    Server-side Requirement: To use this extension, your server-side implementation MUST use the limit (set to pipelineSize) and offset parameters to return only the data within the requested cache window, along with the total number of rows.

  5. Understand the Treegrid data structure

    develop

    The Treegrid extension requires a flat data structure where parent-child relationships are explicitly defined using unique identifiers.

    Requirements:

    • Unique IDs: Every node must have a unique value in the field specified by idField (defaults to id).
    • Parent Links: The field specified by parentIdField (defaults to pid) must contain the idField value of the parent node.
    • Root Nodes: Nodes at the top level should use 0, null, or the value specified in rootParentId as their parent ID.

    Example JSON structure:

    [
      {
        "id": 1,
        "name": "Root Node 1",
        "pid": 0
      },
      {
        "id": 11,
        "name": "Child Node 1.1",
        "pid": 1
      }
    ]
    [
      {
        "id": 1,
        "name": "Root Node 1",
        "pid": 0
      },
      {
        "id": 2,
        "name": "Root Node 2",
        "pid": 0
      },
      {
        "id": 11,
        "name": "Child Node 1.1",
        "pid": 1
      },
      {
        "id": 12,
        "name": "Child Node 1.2",
        "pid": 1
      },
      {
        "id": 111,
        "name": "Grandchild Node 1.1.1",
        "pid": 11
      }
    ]
  6. Understand event parameter order for row clicks

    develop

    The order of parameters in row-click callbacks depends on whether you are using jQuery event delegation or the Bootstrap Table configuration object:

    1. jQuery .on() method: The first parameter is always the standard jQuery event object. Signature: function (event, row, $element)

    2. onClickRow configuration option: The event object is omitted. Signature: function (row, $element)

    // Using jQuery .on()
    $('#eventsTable').on('click-row.bs.table', function (event, row, $element) {
      // event is present
    })
    
    // Using onClickRow option
    {
      onClickRow: function (row, $element) {
        // event is NOT the first parameter
      }
    }
  7. Understand the Bootstrap Table source code structure

    develop

    If you are contributing to the project or building from source, the repository is organized as follows:

    • src/: Contains the source code for the core CSS and JavaScript.
    • src/extensions/: Source code for various extensions.
    • src/locale/: Source code for localization files.
    • src/themes/: Source code for different themes.
    • site/: Contains the source code for the official documentation website.
    • Root files: package.json (package info), LICENSE (licensing), and README.md (development guidelines).
    bootstrap-table/
    ├── site/
    └── src/
        ├── extensions/
        ├── locale/
        ├── themes/
        ├── bootstrap-table.css
        └── bootstrap-table.js
  8. Use rowStyle and cellStyle in print output

    develop

    The Print extension respects the core Bootstrap Table rowStyle and cellStyle options.

    • Inline Styles: The css property (supporting objects, strings, or arrays) is applied to the printed output.
    • Class-based Styles: If you use CSS classes for styling, you must include the relevant CSS file or rules via the printStyles option.
    • Custom Builders: If using printPageBuilder, ensure the styles argument is included in your returned HTML so that class-based styles are available.
  9. Configure Pagination and Server-Side Data

    develop

    Bootstrap Table supports both client-side and server-side pagination via the sidePagination option.

    Client-side Pagination

    • Default: 'client'. The table handles all pagination logic locally with the provided data.

    Server-side Pagination

    • Value: 'server'. Requires setting the url or ajax option.
    • URL Parameters: When using 'server', the table automatically appends the following to your request:
      • offset: The index of the first record to include (0 to total - 1).
      • limit: The number of rows requested per page.
    • Implementation: Your server must return a JSON response that respects these parameters. For example, if requesting records 11-20, your server should process offset=10&limit=10.

    Pagination Display Options

    • showExtendedPagination: Set to true to show an extended pagination view that includes the total count of all rows (even those filtered out). If using server-side pagination, use totalNotFilteredField to specify which field in your JSON contains this count.
    • showPaginationSwitch: Set to true to show a button to switch between pagination modes.
    • totalNotFilteredField: The key in your JSON response used for showExtendedPagination (defaults to totalNotFiltered).
    <!-- Server-side pagination example -->
    <table data-url="/api/data" data-side-pagination="server" data-total-not-filtered-field="all_count"></table>
  10. Prevent parameter collisions with addrPrefix

    develop

    By default, the Addrbar extension uses five standard query parameters:

    • page: page number
    • size: page size
    • order: asc/dsc
    • sort: the sort keyword
    • search: search keyword

    If you have multiple tables on one page, they will all attempt to use these same keys, causing conflicts. To resolve this, set the data-addr-prefix attribute to a unique string for each table. The extension will then prefix the standard parameters with your custom string.