title: Datatables showing two search boxes and pagination data
body: <p>I am trying to integrate datatables into my project.  One of my tables has a button to add additional rows.  I used the method shown <a href="http://www.datatables.net/forums/discussion/8485/add-row-of-inputs-to-match-datatypes/p1" rel="noreferrer">here</a>.  After adding a row and submitting the results, I end up with double datatables controls as shown here:</p>
  
  <p><img src="https://i.stack.imgur.com/FGYVd.png" alt="duplicate datatable controls"></p>
  
  <p><strong>Update</strong></p>
  
  <p>Here is the entire page:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html class="no-js"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
  
              &lt;title&gt;Project name&lt;/title&gt;
  
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width"&gt;
  
          &lt;link rel="shortcut icon" type="image/png" href="/static/images/favicon.ico" /&gt;
  
          &lt;!-- For third-generation iPad with high-resolution Retina display: --&gt;
          &lt;link rel="apple-touch-icon-precomposed" sizes="144x144" href="/static/images/apple-touch-icon-144x144-precomposed.png"&gt;
          &lt;!-- For iPhone with high-resolution Retina display: --&gt;
          &lt;link rel="apple-touch-icon-precomposed" sizes="114x114" href="/static/images/apple-touch-icon-114x114-precomposed.png"&gt;
          &lt;!-- For first- and second-generation iPad: --&gt;
          &lt;link rel="apple-touch-icon-precomposed" sizes="72x72" href="/static/images/apple-touch-icon-72x72-precomposed.png"&gt;
          &lt;!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: --&gt;
          &lt;link rel="apple-touch-icon-precomposed" href="/static/images/apple-touch-icon-precomposed.png"&gt;
  
          &lt;link rel="stylesheet" href="/static/css/bootstrap.min.css"&gt;
  
          &lt;style&gt;
              body {
                  padding-top: 60px;
                  padding-bottom: 40px;
              }
          &lt;/style&gt;
          &lt;link rel="stylesheet" href="/static/css/bootstrap-responsive.min.css"&gt;
          &lt;link rel="stylesheet" href="/static/css/main.css"&gt;
          &lt;script src="/static/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
  
  
  
  &lt;div class="navbar navbar-fixed-top navbar-inverse"&gt;
      &lt;div class="navbar-inner"&gt;
          &lt;div class="container"&gt;
              &lt;a class="brand" href="/"&gt;VBEnergyZone&lt;/a&gt;
              &lt;div class="nav-collapse"&gt;
  
  
  
  &lt;ul class="nav"&gt;
  
      &lt;li&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
      &lt;li class="dropdown"&gt;
          &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;Tools&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
  
  
  
  
  
          &lt;/ul&gt;
      &lt;/li&gt;
  
          &lt;li class="dropdown"&gt;
              &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;Administration&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt;
              &lt;ul class="dropdown-menu"&gt;
                  &lt;li&gt;&lt;a href="/core/customers/"&gt;Customers&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/core/meters/"&gt;Meters&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/core/price_requests/"&gt;Price requests&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/core/suppliers/"&gt;Suppliers&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/core/supplier_groups/"&gt;Supplier groups&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/core/utilities/"&gt;Utilities&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
  
  
          &lt;li&gt;&lt;a href="/core/user_profiles/"&gt;User Profiles&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/admin"&gt;Django Admin&lt;/a&gt;&lt;/li&gt;
  
  &lt;/ul&gt;
  
  &lt;div class="pull-right"&gt;
      &lt;ul class="nav"&gt;
          &lt;li&gt;&lt;a href="/about"&gt;&lt;i class="icon-info-sign icon-white"&gt;&lt;/i&gt; About&lt;/a&gt;&lt;/li&gt;
  
              &lt;a class="btn dropdown-toggle" data-toggle="dropdown" href="#"&gt;&lt;i class="icon-star"&gt;&lt;/i&gt; eevenson&lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
  
  
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a href="/core/user_profiles/eevenson/"&gt;Profile&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="/accounts/password_change/"&gt;Change password&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="/accounts/logout/"&gt;Log out&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
          &lt;div class="container"&gt;
              &lt;div class='messages'&gt;
  
              &lt;/div&gt;
  
  
  
      &lt;h2&gt;A Test Customer&lt;/h2&gt;
      &lt;h3&gt;Customer&lt;/h3&gt;
      &lt;form action="" id="form" enctype="multipart/form-data" method="post"&gt;
  
  
  &lt;div style='display:none'&gt;&lt;input type='hidden' name='csrfmiddlewaretoken' value='NCQ15jA7erX5dAbx20Scr3gWxgaTn3Iq' /&gt; &lt;/div&gt;&lt;ul class='nav nav-tabs'&gt;&lt;li class='active'&gt;&lt;a class='tab' href='#tab0' data-toggle='tab'&gt;Basic information&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab1' data-toggle='tab'&gt;Meters&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab2' data-toggle='tab'&gt;Emails&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab3' data-toggle='tab'&gt;Phone numbers&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab4' data-toggle='tab'&gt;Locations&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab5' data-toggle='tab'&gt;Documents&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class='tab' href='#tab6' data-toggle='tab'&gt;Managers&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/hr&gt;&lt;div  
      class="tab-content" &gt;&lt;div  
      class="tab-pane active"  id="tab0"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;div id="div_id_name" class="control-group"&gt;&lt;label for="id_name" class="control-label requiredField"&gt;
                  Name&lt;span class="asteriskField"&gt;*&lt;/span&gt;&lt;/label&gt;&lt;div class="controls"&gt;&lt;input name="name" value="A Test Customer" class="span4 textinput textInput" maxlength="128" type="text" id="id_name" /&gt; &lt;/div&gt;&lt;/div&gt;&lt;div id="div_id_legal_name" class="control-group"&gt;&lt;label for="id_legal_name" class="control-label "&gt;
                  Legal name
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;input id="id_legal_name" type="text" class="span4 textinput textInput" name="legal_name" maxlength="128" /&gt; &lt;/div&gt;&lt;/div&gt;&lt;div id="div_id_tags" class="control-group"&gt;&lt;label for="id_tags" class="control-label "&gt;
                  Tags
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;input id="id_tags" type="text" class="span4 tagwidget" name="tags" /&gt; &lt;p id="hint_id_tags" class="help-block"&gt;A comma-separated list of tags.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;div id="div_id_duns_number" class="control-group"&gt;&lt;label for="id_duns_number" class="control-label "&gt;
                  Duns number
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;input id="id_duns_number" type="text" class="span4 textinput textInput" name="duns_number" maxlength="9" /&gt; &lt;/div&gt;&lt;/div&gt;&lt;div id="div_id_taxpayer_id_number" class="control-group"&gt;&lt;label for="id_taxpayer_id_number" class="control-label "&gt;
                  Taxpayer ID number
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;input id="id_taxpayer_id_number" type="text" class="span4 textinput textInput" name="taxpayer_id_number" maxlength="9" /&gt; &lt;/div&gt;&lt;/div&gt;&lt;div id="div_id_customer_type" class="control-group"&gt;&lt;label for="id_customer_type" class="control-label "&gt;
                  Customer type
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;select id="id_customer_type" class="span4 select" name="customer_type"&gt;&lt;option value="" selected="selected"&gt;---------&lt;/option&gt;&lt;option value="MUNI"&gt;Munincipality&lt;/option&gt;&lt;option value="SCDT"&gt;School District&lt;/option&gt;&lt;option value="UNIV"&gt;University&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;div id="div_id_active" class="control-group"&gt;&lt;div class="controls"&gt;&lt;label for="id_active" class="checkbox "&gt;&lt;input id="id_active" checked="checked" type="checkbox" class="span4 checkboxinput" name="active" /&gt;
                          Active
  
  
  
  
  
  
  
  
  
  
  
  
                      &lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab1"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;div id="div_id_meter_textarea" class="control-group"&gt;&lt;label for="id_meter_textarea" class="control-label "&gt;
                  List of meters
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;textarea id="id_meter_textarea" rows="10" cols="40" name="meter_textarea" class="span4 textarea"&gt;&lt;/textarea&gt;&lt;p id="hint_id_meter_textarea" class="help-block"&gt;Enter meter ESI IDs one per line.  Meters will become owned             by customer.  New meter ESI IDs will be created as necessary.              Duplicate ESI IDs will be ignored.  Meters owned by a             different customer will change ownership.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;div id="div_id_utility" class="control-group"&gt;&lt;label for="id_utility" class="control-label "&gt;
                  Utility
              &lt;/label&gt;&lt;div class="controls"&gt;&lt;select id="id_utility" class="span4 select" name="utility"&gt;&lt;option value="" selected="selected"&gt;---------&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;fieldset&gt;&lt;legend&gt;Meters&lt;/legend&gt;&lt;input type="hidden" name="meters-TOTAL_FORMS" value="0" id="id_meters-TOTAL_FORMS" /&gt; &lt;input type="hidden" name="meters-INITIAL_FORMS" value="0" id="id_meters-INITIAL_FORMS" /&gt;&lt;input type="hidden" name="meters-MAX_NUM_FORMS" id="id_meters-MAX_NUM_FORMS" /&gt; &lt;table id="meters" class="formsetTable"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;ESI ID&lt;/th&gt;&lt;th&gt;Utility&lt;/th&gt;&lt;th class="vbNoSearchSort"&gt;Delete?&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/fieldset&gt;&lt;/hr&gt;&lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab2"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;fieldset&gt;&lt;legend&gt;Emails&lt;/legend&gt;&lt;input type="hidden" name="emails-TOTAL_FORMS" value="1" id="id_emails-TOTAL_FORMS" /&gt; &lt;input type="hidden" name="emails-INITIAL_FORMS" value="0" id="id_emails-INITIAL_FORMS" /&gt;&lt;input type="hidden" name="emails-MAX_NUM_FORMS" id="id_emails-MAX_NUM_FORMS" /&gt; &lt;table id="emails" class="formsetTable"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Email&lt;/th&gt;&lt;th&gt;Email type&lt;/th&gt;&lt;th class="vbNoSearchSort"&gt;Delete?&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr class="row1"&gt;&lt;td&gt;&lt;input id="id_emails-0-email" type="text" name="emails-0-email" maxlength="75" /&gt; &lt;/td&gt;&lt;td&gt;&lt;input id="id_emails-0-email_type" type="text" name="emails-0-email_type" maxlength="128" /&gt; &lt;/td&gt;&lt;td&gt;&lt;input type="hidden" name="emails-0-id" id="id_emails-0-id" /&gt; &lt;input type="checkbox" name="emails-0-DELETE" id="id_emails-0-DELETE" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;tfoot&gt;&lt;tr style="display:none;" class="template"&gt;&lt;td&gt;&lt;input id="id_emails-NUM-email" type="text" name="emails-NUM-email" maxlength="75" /&gt; &lt;/td&gt;&lt;td&gt;&lt;input id="id_emails-NUM-email_type" type="text" name="emails-NUM-email_type" maxlength="128" /&gt; &lt;/td&gt;&lt;td&gt;&lt;input type="hidden" name="emails-NUM-id" id="id_emails-NUM-id" /&gt; &lt;input type="checkbox" name="emails-NUM-DELETE" id="id_emails-NUM-DELETE" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tfoot&gt;&lt;/table&gt;&lt;/fieldset&gt;&lt;/hr&gt;&lt;input class='addEmail btn btn-primary' name="addRow" value="Add row" /&gt; &lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab3"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab4"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab5"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div  
      class="tab-pane"  id="tab6"&gt;&lt;div  
      class="row" &gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;div  
      class="span4" &gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  
          &lt;div class="btn-toolbar"&gt;
              &lt;input class='btn btn-primary' type="submit" name="submit" value="Submit changes" /&gt;
              &lt;a href="/core/customers/" class="btn btn-primary"&gt;Cancel&lt;/a&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  
  
  
                  &lt;hr/&gt;
  
          &lt;/div&gt;
  
          &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script&gt;window.jQuery || document.write('&lt;script src="/static/js/vendor/jquery-1.8.3.min.js"&gt;&lt;\/script&gt;')&lt;/script&gt;
          &lt;script src="/static/js/vendor/bootstrap.min.js"&gt;&lt;/script&gt;
          &lt;script src="/static/js/main.js"&gt;&lt;/script&gt;
  
  
      &lt;!-- DataTables CSS --&gt;
      &lt;link rel="stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css"&gt;
  
      &lt;!-- DataTables --&gt;
      &lt;script type="text/javascript" charset="utf8" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;    
  
      /* Create an array with the values of all the input boxes in a column */
      $.fn.dataTableExt.afnSortData['dom-text'] = function  ( oSettings, iColumn )
      {
          var aData = [];
          $( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
              aData.push( this.value );
          } );
          return aData;
      }
  
      /* Create an array with the values of all the select options in a column */
      $.fn.dataTableExt.afnSortData['dom-select'] = function  ( oSettings, iColumn )
      {
          var aData = [];
          $( 'td:eq('+iColumn+') select:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
              aData.push( $(this).val() );
          } );
          return aData;
      }
  
      /* Create an array with the values of all the checkboxes in a column */
      $.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, iColumn )
      {
          var aData = [];
          $( 'td:eq('+iColumn+') input:last', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
              aData.push( this.checked==true ? "1" : "0" );
          } );
          return aData;
      }
  
          $(document).ready(function() {
              $('#meters').dataTable(
                  {
                      "aoColumns": [
                          null,
                          null,
                          { "sSortDataType": "dom-checkbox" },
                      ],
                      "aoColumnDefs": [
                          { 
                              "aTargets":     ["vbNoSearchSort"],
                              "bSearchable":  false,
                              "bSortable":    false
                          }
                      ],
                      "bProcessing"   :true,
                      "bStateSave"    :true,
                      "sPaginationType": "full_numbers"
                  }
              );
  
              $('#emails').dataTable(
                  {
                      "aoColumns": [
                          { "sSortDataType": "dom-text" },
                          { "sSortDataType": "dom-text" },
                          { "sSortDataType": "dom-checkbox" },
                      ],
                      "aoColumnDefs": [
                          { 
                              "aTargets":     ["vbNoSearchSort"],
                              "bSearchable":  false,
                              "bSortable":    false
                          }
                      ],
                      "bProcessing"   :true,
                      "bStateSave"    :true,
                      "sPaginationType": "full_numbers"
                  }
              );
  
          } );
      &lt;/script&gt;
  
      &lt;script&gt;
      var emailsTable;
      var metersTable;
  
      $(document).ready(function() {
          $('#form').submit( function() {
              var sData = 
                  emailsTable.$('input')
                  .add(metersTable.$('input'))
                  .add('input')
                  .add('textarea')
                  .add('select')
                  .serialize();
              $.post('', sData, function(data){$('body').html(data); });
              // $.post('', sData, function(data){
              //  var messages = $('.messages', data);
              //  $('.messages').replaceWith(messages);
              // });
              return false;
          } );
  
          emailsTable = $('#emails').dataTable();
          metersTable = $('#meters').dataTable();
      } );
  
      $('.addEmail').click(function(){
          var type = 'emails'
          var total = $('#' + type).dataTable().fnSettings().fnRecordsTotal();
          var tableId = $('#'+ type).attr('id');
          var template = new Array();
  
          $('#'+tableId+' tfoot tr.template td')
          .clone()
          .each(function(){
              $(this).html($(this).html().replace(/NUM/g,total));
          })
          .each(function(){
              template.push($(this).html());
          });
  
          $('#'+tableId).dataTable().fnAddData(template);
          total++;
          $('#id_' + type + '-TOTAL_FORMS').val(total);
  
      });
      &lt;/script&gt;
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Why does adding rows to the table #emails result in duplicate datatable controls after a submit?</p>
  
  <p>For some reason datatables is embedding a div#emails_wrapper inside of another div#emails_wrapper.</p>