Table editor MDB Pro component

Table editor - Bootstrap 5 & Material Design 2.0 plugin

Table Editor is a useful tool for displaying and managing data. The component works similarly to the Datatable (docs) with an additional column for action buttons.

Note: Read the API tab to find all available options and advanced customization


Basic example

You can initialize the component on table element by adding table-editor class to its wrapper. In this version, you don't need any additional JavaScript - set all options as data-attributes (table settings - wrapper element, column settings - th element).

When edit mode is enabled, the user shouldn't be able to interact with other parts of your website, as it can lead to loss of unsaved changes. You can toggle disable state using edit.mdb.tableEditor and exit.mdb.tableEditor events.

Note: search field and add button are not a build-in part of Table Editor, but you can easily initialize those functionalities in the simplest form by adding data-attributes to them (data-select, data-add-entry, and data-target).

Table Editor collects information from HTML markup to create a data structure - the <table> element will be replaced in the DOM with a different node after component initializes.


Company Address Employees
Smith & Johnson Park Lane 2, London 30
P.J. Company Oak Street 7, Aberdeen 80
Food & Wine Netherhall Gardens 3, Hampstead 12
IT Service Warwick Road 14, London 17
A. Jonson Gallery Oaklands Avenue 2, London 4
F.A. Architects Frognal Way 7, Hampstead 4

          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input
                data-search
                data-target="#table_1"
                type="text"
                id="search_table_1"
                class="form-control"
              />
              <label class="form-label" for="search_table_1">Search</label>
            </div>
            <button class="btn btn-primary btn-sm ml-3" data-add-entry data-target="#table_1">
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div
            class="table-editor"
            id="table_1"
            data-entries="5"
            data-entries-options="[5, 10, 15]"
          >
            <table class="table">
              <thead>
                <tr>
                  <th class="th-sm" data-width="250">Company</th>
                  <th class="th-sm" data-width="250" data-sort="false">Address</th>
                  <th class="th-sm" data-width="250" data-sort="false">Employees</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>Smith & Johnson</td>
                  <td>Park Lane 2, London</td>
                  <td>30</td>
                </tr>
                <tr>
                  <td>P.J. Company</td>
                  <td>Oak Street 7, Aberdeen</td>
                  <td>80</td>
                </tr>
                <tr>
                  <td>Food & Wine</td>
                  <td>Netherhall Gardens 3, Hampstead</td>
                  <td>12</td>
                </tr>
                <tr>
                  <td>IT Service</td>
                  <td>Warwick Road 14, London</td>
                  <td>17</td>
                </tr>
                <tr>
                  <td>A. Jonson Gallery</td>
                  <td>Oaklands Avenue 2, London</td>
                  <td>4</td>
                </tr>
                <tr>
                  <td>F.A. Architects</td>
                  <td>Frognal Way 7, Hampstead</td>
                  <td>4</td>
                </tr>
              </tbody>
            </table>
          </div>
        

Modal

To change the default editing mode (inline) to the modal version, set option mode to "modal".



          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input
                data-search
                data-target="#table_modal"
                type="text"
                id="search_modal"
                class="form-control"
              />
              <label class="form-label" for="search_modal">Search</label>
            </div>
            <button class="btn btn-primary btn-sm ml-3" data-add-entry data-target="#table_modal">
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div id="table_modal"></div>
        

          const advancedColumns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              sort: false,
              defaultValue: 'Warsaw',
              options: ['London', 'Warsaw', 'New York'],
              inputType: 'select',
              label: 'Office',
              field: 'office',
            },
            {
              width: 250,
              inputType: 'number',
              defaultValue: 1,
              label: 'Employees',
              field: 'employees',
            },
            {
              width: 100,
              defaultValue: false,
              inputType: 'checkbox',
              label: 'International',
              field: 'international',
            },
          ];
      
          const advancedRows = [
            {
              company: 'Smith & Johnson',
              office: 'London',
              employees: 30,
              international: true,
            },
            {
              company: 'P.J. Company',
              office: 'London',
              employees: 80,
              international: false,
            },
            {
              company: 'Food & Wine',
              office: 'London',
              employees: 12,
              international: false,
            },
            {
              company: 'IT Service',
              office: 'London',
              employees: 17,
              international: false,
            },
            {
              company: 'A. Jonson Gallery',
              office: 'London',
              employees: 4,
              international: false,
            },
            {
              company: 'F.A. Architects',
              office: 'London',
              employees: 4,
              international: false,
            },
          ];
      
          const tableModal = new TableEditor(
          document.getElementById('table_modal'),
          {
            columns: advancedColumns,
            rows: advancedRows,
          },
          { mode: 'modal', entries: 5, entriesOptions: [5, 10, 15] }
        );
        

Inputs example

Table Editor supports several input types - for example, if you wish to force a user to enter only Boolean values in one column, you can set its inputType to a checkbox.

Supported input types:

  • Text (default)
  • Number
  • Checkbox - displays a checkbox in edit mode and true/false value otherwise
  • Select - additionally requires an array of options


          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input data-search data-target="#table_inputs" type="text" id="search_table_inputs" class="form-control" />
              <label class="form-label" for="search_table_inputs">Search</label>
            </div>
            <button class="btn btn-primary btn-sm ml-3" data-add-entry data-target="#table_inputs">
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div id="table_inputs"></div>
        

          const advancedColumns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              sort: false,
              defaultValue: 'Warsaw',
              options: ['London', 'Warsaw', 'New York'],
              inputType: 'select',
              label: 'Office',
              field: 'office',
            },
            {
              width: 250,
              inputType: 'number',
              defaultValue: 1,
              label: 'Employees',
              field: 'employees',
            },
            {
              width: 100,
              defaultValue: false,
              inputType: 'checkbox',
              label: 'International',
              field: 'international',
            },
          ];
      
          const advancedRows = [
            {
              company: 'Smith & Johnson',
              office: 'London',
              employees: 30,
              international: true,
            },
            {
              company: 'P.J. Company',
              office: 'London',
              employees: 80,
              international: false,
            },
            {
              company: 'Food & Wine',
              office: 'London',
              employees: 12,
              international: false,
            },
            {
              company: 'IT Service',
              office: 'London',
              employees: 17,
              international: false,
            },
            {
              company: 'A. Jonson Gallery',
              office: 'London',
              employees: 4,
              international: false,
            },
            {
              company: 'F.A. Architects',
              office: 'London',
              employees: 4,
              international: false,
            },
          ];
      
          const tableDisableEdit = new TableEditor(
            document.getElementById('table_inputs'),
            { columns: advancedColumns, rows: advancedRows },
            { entries: 5, entriesOptions: [5, 10, 15] }
          );
        

Disable edit

You can disable editing for a column by setting its editable option to false. A user won't be able to change its value in the edit mode.



          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input
                data-search
                data-target="#table_disable_edit"
                type="text"
                id="search_disable_edit"
                class="form-control"
              />
              <label class="form-label" for="search_disable_edit">Search</label>
            </div>
            <button
              class="btn btn-primary btn-sm ml-3"
              data-add-entry
              data-target="#table_disable_edit"
            >
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div id="table_disable_edit"></div>
        

          const advancedColumns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              sort: false,
              defaultValue: 'Warsaw',
              options: ['London', 'Warsaw', 'New York'],
              inputType: 'select',
              label: 'Office',
              field: 'office',
            },
            {
              width: 250,
              inputType: 'number',
              defaultValue: 1,
              label: 'Employees',
              field: 'employees',
            },
            {
              width: 100,
              defaultValue: false,
              inputType: 'checkbox',
              label: 'International',
              field: 'international',
            },
          ];
      
          const advancedRows = [
            {
              company: 'Smith & Johnson',
              office: 'London',
              employees: 30,
              international: true,
            },
            {
              company: 'P.J. Company',
              office: 'London',
              employees: 80,
              international: false,
            },
            {
              company: 'Food & Wine',
              office: 'London',
              employees: 12,
              international: false,
            },
            {
              company: 'IT Service',
              office: 'London',
              employees: 17,
              international: false,
            },
            {
              company: 'A. Jonson Gallery',
              office: 'London',
              employees: 4,
              international: false,
            },
            {
              company: 'F.A. Architects',
              office: 'London',
              employees: 4,
              international: false,
            },
          ];
      
          const tableDisableEdit = new TableEditor(
          document.getElementById('table_disable_edit'),
          {
            columns: advancedColumns.map((column) => {
              return {
                ...column,
                editable: false,
              };
            }),
            rows: advancedRows,
          },
          { entries: 5, entriesOptions: [5, 10, 15] }
        );
        

Confirm delete

If you want to prevent data from being accidentally removed, you can set a confirm option to true. In this case, Table Editor will show a Popconfirm element before removing an entry.



          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input
                data-search
                data-target="#table_confirm_delete"
                type="text"
                id="search_confirm_delete"
                class="form-control"
              />
              <label class="form-label" for="search_confirm_delete">Search</label>
            </div>
            <button
              class="btn btn-primary btn-sm ml-3"
              data-add-entry
              data-target="#table_confirm_delete"
            >
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div id="table_confirm_delete"></div>
        

          const advancedColumns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              sort: false,
              defaultValue: 'Warsaw',
              options: ['London', 'Warsaw', 'New York'],
              inputType: 'select',
              label: 'Office',
              field: 'office',
            },
            {
              width: 250,
              inputType: 'number',
              defaultValue: 1,
              label: 'Employees',
              field: 'employees',
            },
            {
              width: 100,
              defaultValue: false,
              inputType: 'checkbox',
              label: 'International',
              field: 'international',
            },
          ];
      
          const advancedRows = [
            {
              company: 'Smith & Johnson',
              office: 'London',
              employees: 30,
              international: true,
            },
            {
              company: 'P.J. Company',
              office: 'London',
              employees: 80,
              international: false,
            },
            {
              company: 'Food & Wine',
              office: 'London',
              employees: 12,
              international: false,
            },
            {
              company: 'IT Service',
              office: 'London',
              employees: 17,
              international: false,
            },
            {
              company: 'A. Jonson Gallery',
              office: 'London',
              employees: 4,
              international: false,
            },
            {
              company: 'F.A. Architects',
              office: 'London',
              employees: 4,
              international: false,
            },
          ];
          
          const tableConfirmDelete = new TableEditor(
            document.getElementById('table_confirm_delete'),
            {
              columns: advancedColumns,
              rows: advancedRows,
            },
            { entries: 5, entriesOptions: [5, 10, 15], confirm: true }
          );
        );
        


Async data

While awaiting data from API, you can prevent a user from interacting with Table Editor by setting loading option to true.



          <div class="d-flex justify-content-between mb-4">
            <button id="async_data_btn" class="btn btn-primary btn-sm">
              Load data
            </button>
            <div class="d-flex">
              <div class="form-outline">
                <input
                  type="text"
                  data-search
                  data-target="#table_async_data"
                  id="search_async"
                  class="form-control"
                />
                <label class="form-label" for="search_async">Search</label>
              </div>
              <button
                class="btn btn-primary btn-sm ml-3"
                data-add-entry
                data-target="#table_async_data"
              >
                <i class="fa fa-plus"></i>
              </button>
            </div>
          </div>
          <hr />
          <div id="table_async_data"></div>
        

          const table = document.getElementById('table_async_data');
          const loadBtn = document.getElementById('async_data_btn');

          const columns = [
            { label: 'Company', field: 'company' },
            { label: 'Email', field: 'email' },
            { label: 'Name', field: 'name' },
            { label: 'Phone', field: 'phone' },
          ];

          const asyncTable = new TableEditor(
            table,
            {
              columns,
            },
            {
              loading: true,
            }
          );

          const loadData = () => {
            asyncTable.update(null, { loading: true });

            fetch('https://jsonplaceholder.typicode.com/users')
              .then((response) => response.json())
              .then((data) => {
                asyncTable.update(
                  {
                    rows: data.map((user) => ({
                      ...user,
                      address: `${user.address.city}, ${user.address.street}`,
                      company: user.company.name,
                    })),
                  },
                  { loading: false }
                );
              });
          };

          loadBtn.addEventListener('click', loadData);

          table.addEventListener('update.mdb.tableEditor', e => {
            // here you can create a POST request to update your database
            console.log(e.columns, e.rows);
          })
        

Custom rows

The add() method takes an optional argument - a row which values will be preloaded into a new entry.

Note: for this particular use, a row has to be an object.

Note: as adding buttons are initialized manually, they won't be automatically disabled in the edit mode.

M.B.

(5 Avenue 26, New York)

Berkley & Clark

(43th Street 12, New York)

D&D Inc.

(14 Street 67, New York)

Thomas & Co.

(2 Avenue 54, New York)



          <div id="template_list" class="row">
            <div class="col-md-3 col-sm-6 p-3">
              <h4>M.B.</h4>
              <p>(5 Avenue 26, New York)</p>
              <button
                class="btn btn-primary btn-sm add-entry-button"
                data-company="M.B."
                data-address="5 Avenue 26"
                data-city="New York"
              >
                Load into table
              </button>
            </div>
            <div class="col-md-3 col-sm-6 p-3">
              <h4>Berkley & Clark</h4>
              <p>(43th Street 12, New York)</p>
              <button
                class="btn btn-primary btn-sm add-entry-button"
                data-company="Berkley & Clark"
                data-address="43th Street 12"
                data-city="New York"
              >
                Load into table
              </button>
            </div>
            <div class="col-md-3 col-sm-6 p-3">
              <h4>D&D Inc.</h4>
              <p>(14 Street 67, New York)</p>
              <button
                class="btn btn-primary btn-sm add-entry-button"
                data-company="D&D Inc."
                data-address="14 Street 67"
                data-city="New York"
              >
                Load into table
              </button>
            </div>
            <div class="col-md-3 col-sm-6 p-3">
              <h4>Thomas & Co.</h4>
              <p>(2 Avenue 54, New York)</p>
              <button
                class="btn btn-primary btn-sm add-entry-button"
                data-company="Thomas & Co."
                data-address="2 Avenue 54"
                data-city="New York"
              >
                Load into table
              </button>
            </div>
          </div>
          <hr class="mt-3" />
          <div id="table_custom_rows"></div>
        

          const columns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              label: 'Address',
              field: 'address',
            },
            {
              width: 250,
              label: 'City',
              field: 'city',
            },
          ];

          const rows = [
            { company: 'Smith & Johnson', address: 'Park Lane 2', city: 'London' },
            { company: 'P.J. Company', address: 'Oak Street 7', city: 'Aberdeen' },
            { company: 'Food & Wine', address: 'Netherhall Gardens 3', city: 'Hampstead' },
            { company: 'IT Service', address: 'Warwick Road 14', city: 'London' },
            { company: 'A. Jonson Gallery', address: 'Oaklands Avenue 2', city: 'London' },
            { company: 'F.A. Architects', address: 'Frognal Way 7', city: 'Hampstead' },
          ];

          const table = document.getElementById('table_custom_rows');

          const tableEditorInstance = new TableEditor(table, { rows, columns }, { pagination: false });

          const buttons = document.getElementsByClassName('add-entry-button');

          buttons.forEach((button) => {
            button.addEventListener('click', (e) => {
              const company = e.target.getAttribute('data-company');
              const address = e.target.getAttribute('data-address');
              const city = e.target.getAttribute('data-city');

              tableEditorInstance.add({ company, address, city });

              e.target.setAttribute('disabled', true);
              e.target.innerText = 'Loaded';
            });
          });

          // disable buttons in edit mode

          table.addEventListener('edit.mdb.tableEditor', () => {
            buttons.forEach((button) => {
              button.setAttribute('disabled', true);
            });
          });

          table.addEventListener('exit.mdb.tableEditor', () => {
            buttons.forEach((button) => {
              if (button.innerText.toLowerCase() !== 'loaded') {
                button.removeAttribute('disabled');
              }
            });
          });
        

Notifications

In this example, handlers for custom events trigger notifications after adding/deleting/updating an entry.



          <div class="d-flex justify-content-end mb-4">
            <div class="form-outline">
              <input
                data-search
                data-target="#table_notifications"
                type="text"
                id="search_table_notifications"
                class="form-control"
              />
              <label class="form-label" for="search_table_notifications">Search</label>
            </div>
            <button
              class="btn btn-primary btn-sm ml-3"
              data-add-entry
              data-target="#table_notifications"
            >
              <i class="fa fa-plus"></i>
            </button>
          </div>
          <hr />
          <div id="table_notifications"></div>
          <div
            class="alert fade"
            id="alert-add-entry"
            role="alert"
            data-position="top-right"
            data-autohide="true"
            data-width="360px"
            data-color="success"
          >
          </div>
          <div
            class="alert fade"
            id="alert-update-entry"
            role="alert"
            data-position="top-right"
            data-autohide="true"
            data-width="360px"
            data-color="primary"
          ></div>
          <div
            class="alert fade"
            id="alert-remove-entry"
            role="alert"
            data-position="top-right"
            data-autohide="true"
            data-width="360px"
            data-color="danger"
          >
          </div>
        

          const advancedColumns = [
            {
              width: 250,
              label: 'Company',
              field: 'company',
            },
            {
              width: 250,
              sort: false,
              defaultValue: 'Warsaw',
              options: ['London', 'Warsaw', 'New York'],
              inputType: 'select',
              label: 'Office',
              field: 'office',
            },
            {
              width: 250,
              inputType: 'number',
              defaultValue: 1,
              label: 'Employees',
              field: 'employees',
            },
            {
              width: 100,
              defaultValue: false,
              inputType: 'checkbox',
              label: 'International',
              field: 'international',
            },
          ];

          const advancedRows = [
            {
              company: 'Smith & Johnson',
              office: 'London',
              employees: 30,
              international: true,
            },
            {
              company: 'P.J. Company',
              office: 'London',
              employees: 80,
              international: false,
            },
            {
              company: 'Food & Wine',
              office: 'London',
              employees: 12,
              international: false,
            },
            {
              company: 'IT Service',
              office: 'London',
              employees: 17,
              international: false,
            },
            {
              company: 'A. Jonson Gallery',
              office: 'London',
              employees: 4,
              international: false,
            },
            {
              company: 'F.A. Architects',
              office: 'London',
              employees: 4,
              international: false,
            },
          ];

          const table = document.getElementById('table_notifications');

          new TableEditor(table, { rows: advancedRows, columns: advancedColumns });

          table.addEventListener('add.mdb.tableEditor', (e) => {
            const alert = document.getElementById('alert-add-entry');
            const alertInstance = mdb.Alert.getInstance(alert);

            const { company, office } = e.row;
            alert.innerHTML = `<strong>New entry:</strong> ${company} (${office})`;
            
            alertInstance.show();
          });

          table.addEventListener('delete.mdb.tableEditor', (e) => {
            const alert = document.getElementById('alert-remove-entry');
            const alertInstance = mdb.Alert.getInstance(alert);

            const { company, office } = e.row;
            alert.innerHTML = `<strong>Deleted entry:</strong> ${company} (${office})`;
            
            alertInstance.show();
          });

          table.addEventListener('updateEntry.mdb.tableEditor', (e) => {
            const alert = document.getElementById('alert-update-entry');
            const alertInstance = mdb.Alert.getInstance(alert);

            const { company, office } = e.row;
            alert.innerHTML = `<strong>Updated entry:</strong> ${company} (${office})`;
            
            alertInstance.show();
          });
        

Dark

Dark mode can be applied to both modal and inline versions - firstly, add a CSS class which changes the background color to your page. Secondly, pass the same class name to the color option of your Table Editor (f.e. 'bg-dark'). Now change the font to light by setting dark attribute to true.

Tip: add form-white class to your search input's wrapper.


Company Address Employees
Smith & Johnson Park Lane 2, London 30
P.J. Company Oak Street 7, Aberdeen 80
Food & Wine Netherhall Gardens 3, Hampstead 12
IT Service Warwick Road 14, London 17
A. Jonson Gallery Oaklands Avenue 2, London 4
F.A. Architects Frognal Way 7, Hampstead 4

          <div class="bg-dark">
            <div class="d-flex justify-content-end mb-4">
              <div class="form-outline form-white">
                <input
                  data-search
                  data-target="#table_dark"
                  type="text"
                  id="search_table_dark"
                  class="form-control"
                />
                <label class="form-label" for="search_table_dark">Search</label>
              </div>
              <button
                class="btn btn-outline-light btn-sm ml-3"
                data-add-entry
                data-target="#table_dark"
              >
                <i class="fa fa-plus"></i>
              </button>
            </div>
            <hr />
            <div
              class="table-editor bg-dark"
              id="table_dark"
              data-mode="modal"
              data-dark="true"
              data-entries="5"
              data-entries-options="[5, 10, 15]"
            >
              <table class="table">
                <thead>
                  <tr>
                    <th class="th-sm" data-width="250">Company</th>
                    <th class="th-sm" data-width="250">Address</th>
                    <th class="th-sm" data-width="250">
                      Employees
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <td>Smith & Johnson</td>
                    <td>Park Lane 2, London</td>
                    <td>30</td>
                  </tr>
                  <tr>
                    <td>P.J. Company</td>
                    <td>Oak Street 7, Aberdeen</td>
                    <td>80</td>
                  </tr>
                  <tr>
                    <td>Food & Wine</td>
                    <td>Netherhall Gardens 3, Hampstead</td>
                    <td>12</td>
                  </tr>
                  <tr>
                    <td>IT Service</td>
                    <td>Warwick Road 14, London</td>
                    <td>17</td>
                  </tr>
                  <tr>
                    <td>A. Jonson Gallery</td>
                    <td>Oaklands Avenue 2, London</td>
                    <td>4</td>
                  </tr>
                  <tr>
                    <td>F.A. Architects</td>
                    <td>Frognal Way 7, Hampstead</td>
                    <td>4</td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        

Table editor - API


Usage

Via data attributes

Using the Table Editor component doesn't require any additional JavaScript code - simply add a div wrapper with a class "table-editor" to your table and use data attributes to set all options.


        <div class="d-flex justify-content-end mb-4">
          <div class="form-outline">
            <input
              data-search
              data-target="#table_1"
              type="text"
              id="search_table_1"
              class="form-control"
            />
            <label class="form-label" for="search_table_1">Search</label>
          </div>
          <button class="btn btn-primary btn-sm ml-3" data-add-entry data-target="#table_1">
            <i class="fa fa-plus"></i>
          </button>
        </div>
        <hr />
        <div
          class="table-editor"
          id="table_1"
          data-mode="modal"
          data-entries="5"
          data-entries-options="[5, 10, 15]"
        >
          <table></table>
        </div>
      

Via JavaScript

If you prefer to render a table with JavaScript, initialize an instance with the TableEditor constructor.


        const table = document.getElementById('my-table');
        const tableEditor = new TableEditor(table, { rows: [], columns: [], { 
          mode: 'modal', 
          entries: 5, 
          entriesOptions: [5, 10, 15]
        }})
      

Via jQuery

Note: By default, MDB does not include jQuery and you have to add it to the project on your own.


        $('#my-tableEditor').tableEditor({
          columns: [
            { label: 'Column 1', width: 100, fixed: true, sort: false },
            { label: 'Column 2'}
          ],
          rows: [
            ['Value 1', 'Value 2']
          ]
        }, {
           bordered: true
        })

        // Calling .update() with the jQuery interface:

        $('#my-tableEditor').tableEditor('update', { rows: [...], columns: [...]}, { bordered: true, loading: false })
      

Options

Name Type Default Description
actionHeader String 'Actions' Header for action buttons
actionPosition String 'end' Decides where to render an action column (start/end)
bordered Boolean false Adds borders to a datatable
borderless Boolean false Removes all borders from a datatable
borderColor String Changes a border color to one of main colors
cancelText String 'Cancel' Text displayed in cancel buttons
confirm Boolean false Displays a Popconfirm element before removing an entry
confirmText String 'Delete' Text displayed in confirm buttons (Popconfirm)
confirmMessage String 'Are you sure you want to delete this entry?' Text displayed in a Popconfirm element
color String Adds a color class to a datatable (f.e 'bg-dark')
dark Boolean false Changes a font color to white
defaultValue String '-' This string will be used as a placeholder if a row doesn't have a defined value for a column
entries Number 10 Number of visible entries (pagination)
entriesOptions Array [10, 25, 50, 200] Options available to choose from in a pagination select (rows per page)
fixedHeader Boolean false When it's set to true, the table's header will remain visible while scrolling
fullPagination Boolean false Displays additional buttons for the first and last pages
hover Boolean false Changes the background color of a hovered row
loading Boolean false Sets the loading mode - disables interactions and displays a loader
loaderClass String 'bg-primary' The class name for a loader (loading mode)
loadingMessage String 'Loading results...' A message displayed while loading data
maxWidth Number|String Sets a maximum width of a datatable - can be either a string ('10%') or a number of pixels.
maxHeight Number|String Sets a maximum height of a datatable - can be either a string ('10%') or a number of pixels.
mode String 'inline' Changes edit mode - available options: 'inline', 'modal'
newItemHeader String 'New item' A header of modal
noFoundMessage String 'No matching results found' A message displayed when a table is empty
pagination Boolean true Shows/hides the pagination panel
saveText String 'Save' Text displayed in the save button (modal)
sm Boolean false Decreases a row's paddings
striped Boolean false Slightly changes the background's color in every other row
rowsText String 'Rows per page': A text indicating a number of rows per page

Options (column)

Name Type Default Description
defaultValue String Default value only for one column
editable Boolean true Enables/disabled editing fields in this column
field String '' A field's name - will be used as a key for values in rows
fixed Boolean|String false When set to true, makes a column stick on the left while scrolling. Changing its value to right will do the same on the other side. For this option to work, you need to define width as well.
inputType String 'text' Input type for a column. Available options: 'text', 'number', 'checkbox', 'select'
label String '' A displayed header of a column
options Array Array of options (for column with a "select" input type)
sort Boolean true Enables/disables sorting for this column
width Number A column's width in pixels

Methods

Name Description Example
add Adds a new row (default values are optional) instance.add(row: Object)
update Updates and rerenders datatable instance.update(data: Object, options: Object)
search Filters rows so there are only those containing the searched phrase instance.search(phrase: String, column: String|Array (optional))
dispose Removes the component's instance instance.dispose()

Events

Name Description
add.mdb.tableEditor This event fires after adding a new row
delete.mdb.tableEditor This event fires after deleting a row
edit.mdb.tableEditor This event fires when user enters edit mode
exit.mdb.tableEditor This event fires when user exits edit mode
update.mdb.tableEditor This event fires in an editable mode when a user updates values. You can access the upsdated data inside a listener's handler with event.rows and event.columns fields.
updateEntry.mdb.tableEditor This event fires after saving changes in an existing row.
render.mdb.tableEditor Event emitted after the component renders/updates rows.

Import

MDB UI KIT also works with module bundlers. Use the following code to import this component:


        import { TableEditor } from 'mdb-table-editor';