Hello.
Below is the code that forms the table - dataTables in which there is a quick search, sorting the columns by name and there is a button by pressing, which is added to the line above and filled with such information
1.1 1.2 1.3
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script> <script src="js/dataTables.bootstrap.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/jquery.dataTables.min.css"> <link rel="stylesheet" href="css/dataTables.bootstrap.min.css"> <script type="text/javascript"> $(document).ready(function() { var dataSet = [ [ "Tiger", "Nixon", "user1"], [ "Garrett", "Winters", "user2", ] ]; var t = $('#example').DataTable( { data: dataSet, columns: [ { title: "Π€Π°ΠΌΠΈΠ»ΠΈΡ" }, { title: "ΠΠΌΡ" }, { title: "ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ" } ] } ); var counter = 1; $('#addRow').on( 'click', function () { t.row.add( [ counter +'.1', counter +'.2', counter +'.3' ] ).draw( false ); counter++; } ); // Automatically add a first row of data $('#addRow').click(); } ); </script> <div class="container"> <button id="addRow" class="btn btn-success"><i class="glyphicon glyphicon-ok-sign" ></i> ΠΠΎΠ±Π°Π²ΠΈΡΡ ΡΡΡΠΎΠΊΡ</button> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Π€Π°ΠΌΠΈΠ»ΠΈΡ</th> <th>ΠΠΌΡ</th> <th>ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ</th> </tr> </thead> <tfoot> <tr> <th>Π€Π°ΠΌΠΈΠ»ΠΈΡ</th> <th>ΠΠΌΡ</th> <th>ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ</th> </tr> </tfoot> </table> </div>
<script src="js/jquery.dataTables.min.js" type="text/javascript"></script> <script src="js/dataTables.bootstrap.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/jquery.dataTables.min.css"> <link rel="stylesheet" href="css/dataTables.bootstrap.min.css"> <script type="text/javascript"> $(document).ready(function() { var dataSet = [ [ "Tiger", "Nixon", "user1"], [ "Garrett", "Winters", "user2", ] ]; var t = $('#example').DataTable( { data: dataSet, columns: [ { title: "Π€Π°ΠΌΠΈΠ»ΠΈΡ" }, { title: "ΠΠΌΡ" }, { title: "ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ" } ] } ); var counter = 1; $('#addRow').on( 'click', function () { t.row.add( [ counter +'.1', counter +'.2', counter +'.3' ] ).draw( false ); counter++; } ); // Automatically add a first row of data $('#addRow').click(); } ); </script> <div class="container"> <button id="addRow" class="btn btn-success"><i class="glyphicon glyphicon-ok-sign" ></i> ΠΠΎΠ±Π°Π²ΠΈΡΡ ΡΡΡΠΎΠΊΡ</button> <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>Π€Π°ΠΌΠΈΠ»ΠΈΡ</th> <th>ΠΠΌΡ</th> <th>ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ</th> </tr> </thead> <tfoot> <tr> <th>Π€Π°ΠΌΠΈΠ»ΠΈΡ</th> <th>ΠΠΌΡ</th> <th>ΠΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ</th> </tr> </tfoot> </table> </div>
The problem is that even at the initial launch of the form, an event of adding a row is immediately triggered.
Tell me where the error is.