1.3.16 • Published 1 year ago

dynamicrows v1.3.16

Weekly downloads
81
License
ISC
Repository
github
Last release
1 year ago

dynamicrows

jQuery-plugin for add/remove rows by cloning existing row / renaming form-elements (arrays).


Requirements

  • jQuery >=2.0
  • if move-action used: sortablejs (recommended) or jQuery UI

Installation

npm:

npm install dynamicrows --save

Bower (deprecated):

bower install debrouchee/dynamicrows --save

Or download js/dynamicrows.min.js and include the script on your page like shown below.


Usage

ECMAScript:

require('dynamicrows');

or direct include script:

<script src="dynamicrows.min.js"></script>

Markup example:

<table data-dynamicrows>
  <thead>
    <tr>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>E-Mail</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type="text" name="contacts[0][firstname]"></td>
      <td><input type="text" name="contacts[0][lastname]"></td>
      <td><input type="text" name="contacts[0][email]"></td>
      <td>
        <i class="fa fa-minus" data-remove></i>
        <i class="fa fa-arrows" data-move></i>
        <i class="fa fa-plus" data-add></i>
      </td>
    </tr>
  </tbody>
</table>

Initialize:

$(function() {
  $('table[data-dynamicrows]').dynamicrows(options);
});

Advanced markup example

<table data-dynamicrows data-increment=".increment" data-row=".row" data-form-prefix="contacts[874]">
  <thead>
    <tr>
      <th>Pos.</th>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>E-Mail</th>
    </tr>
  </thead>
  <tbody>
    <tr class="row">
      <td><span class="increment">1</span>.</td>
      <td><input type="text" name="contacts[874][0][firstname]"></td>
      <td><input type="text" name="contacts[874][0][lastname]"></td>
      <td><input type="text" name="contacts[874][0][email]"></td>
      <td><input type="date" name="contacts[874][0][date]" class="datepicker"></td>
      <td>
        <i class="fa fa-minus" data-remove></i>
        <i class="fa fa-arrows" data-move></i>
        <i class="fa fa-plus" data-add></i>
      </td>
    </tr>
  </tbody>
</table>

Initialize:

$(function() {
  $('table[data-dynamicrows]').dynamicrows({
    beforeAdd: function($row) {
      let confirm_result = confirm('Möchten Sie wirklich eine neue Zeile hinzufügen?');
      if (!confirm_result) {
        return false;
      }
      $row.find('.datepicker').datepicker('remove');
    },
    afterAdd: function($row) {
      $row.find('.datepicker').datepicker();
    }
  });
});

Options

OptionDefaultDescription
rowtrrow selector
rowstbodyrows-container selector
minrows1minimum of rows
copy_rownullrow selector for template-row
copy_valuesfalseif true input-values are copied
incrementnullselector for placing row numbering
handle_add[data-add]selector for adding new row
handle_remove[data-remove]selector for removing row
handle_move[data-move]selector for moving row
index_start0starting index for input array names
form_prefix | prefix of input-elements to be ignored in updateFormNames()
prevent_renamingfalseprevent auto-renaming of input-elements
animationfalseuse jQuery animation method (fade)
animation_speed300animation speed in milliseconds
beforeAddnullcallback function
beforeRemovenullcallback function
beforeFormUpdateNamesnullcallback function
beforeAllnullcallback function
beforeMovenullcallback function
afterAddnullcallback function
afterRemovenullcallback function
afterMovenullcallback function
afterFormUpdateNamesnullcallback function
afterAllnullcallback function

1.3.16

1 year ago

1.3.15

4 years ago

1.3.14

4 years ago

1.3.13

4 years ago

1.3.12

4 years ago

1.3.10

4 years ago

1.3.11

4 years ago

1.3.9

4 years ago

1.3.8

5 years ago

1.3.6

6 years ago

1.0.0

6 years ago