Git Product home page Git Product logo

bootstrap-table-toolbar-buttons's Introduction

Custom Toolbar Buttons

This is an extension of Bootstrap table to add custom buttons to toolbar, close to default buttons like "refresh", "column selector", etc.

Features

  • Add a custom button with specified icon that on click event call a custom function

Demo

See it in action: demo here

Installation

Bower

bower install bootstrap-table-toolbar-buttons

Usage

Include this extension after Bootstrap-table. In case you use an AMD loader (like require.js) specify manually dependecies to jQuery, bootstrap and bootstrap-table (like shims in require.js).

<script src="bootstrap-table-toolbar-buttons.js"></script>

Simple example:

<body>
    <div class="container">
      <div class="row">
        <table id='grid'>
            <thead>
              <tr>
                <th data-field='itemid'>Item ID</th>
                <th data-field='name'>Name</th>
                <th data-field='price'>Price</th>
              </tr>
            </thead>
            <tbody>
              <tr><td>1</td><td>ABC</td><td>$1.00</td></tr>
              <tr><td>2</td><td>DEF</td><td>$2.00</td></tr>
              <tr><td>3</td><td>GHI</td><td>$3.00</td></tr>
              <tr><td>4</td><td>XYZ</td><td>$4.00</td></tr>
            </tbody>
        </table>
      </div>  
    </div>
  
    <!-- context menu -->
    <ul id="context-menu" class="dropdown-menu">
        <li data-item="edit"><a>Edit</a></li>
        <li data-item="delete"><a>Delete</a></li>
        <li data-item="action1"><a>Action Here</a></li>
        <li data-item="action2"><a>And Action Here</a></li>
    </ul>  

    <div id="filters-dialog" class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title ">Table Filters</h4>
                </div>
                <div class="modal-body">
                    <span>Add here filter fields!</span>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger pull-left">Reset Filters</button>
                    <button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>    

    <script>
    $(function() {
        $('#grid').bootstrapTable({
            showRefresh: true,
            customToolbarButtons: [
                {
                    name: "grid-filters",
                    title: "Filters",
                    icon: "glyphicon-filter",
                    callback: onShowFiltersDialog
                }
            ]
        });
    });

    var onShowFiltersDialog = function(){
        $('#filters-dialog').modal('show');
    }
    </script>
</body>

Options

Name Type Default Description
customToolbarButtons Array [] An array of button object (see below).

Button object

Name Type Default Description
name String undefined The attribute NAME of the button. It must be unique else just one button will be rendered.
title String undefined The attribute TITLE and ARIA-LABEL of the button.
icon String undefined The css class name of the button (usually a glyphicon), it depend on the option iconsPrefix.
callback Function undefined The function will be called when user raise CLICK event to the button.

bootstrap-table-toolbar-buttons's People

Contributors

michaelsogos avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.