Adding a new row to my data table

Adding a new row to my data table

baokybaoky Posts: 8Questions: 6Answers: 0

My data set currently have 7 columns, I want to add a new row to my current data table at column 7, which is action column, whereby I will want add my submit button

<input type="submit" class="btn btn-primary" value="Apply Changes">

How do I amend my datatable code below to add a new row, at column 7.
The Col 1 to 6 can leave as empty value

My dataset code is generate using php

$data .= "['" . $row_username . "','" . $row_name . "','" . $telephone. "','"  . $zip_code. "','" . $country. "','"  . $description. "','" . $value.  "','" . $action . "'],";

I tried to use the following after .draw() function and its not working

 table.row.add( [
            '',
            '',
            '',
            '',
            '',
            '',
            '<input type="submit" class="btn btn-primary" value="Apply Changes">',
        ] ).draw();

Below is my data table code

           $(document).ready(function() {

                var dataSet = [
                   <?=$data;?>
                ];
                $('#example1').dataTable({
                    "order": [[ 0, "desc" ]],
                    "data": dataSet,
<?php 
echo "\"sDom\": '<\"top\"iflp>rt<\"bottom\"p><\"clear\">'";
?>
                });


                // Setup - add a text input to each footer cell
                var tbnum = 0;
                $('#example1 thead td').each( function () {
                    var title = $('#example1 thead th').eq( $(this).index() ).text();
                    $(this).html( '<input type="text" class="search'+ tbnum +'" placeholder=" " />' );
                    tbnum+=1;

               } );

                // DataTable
                var table = $('#example1').DataTable();
                // Apply the search
                 table.columns().eq( 0 ).each( function ( colIdx ) {
//                     alert(colIdx);
                    $( '.filters .search'+colIdx).on( 'keyup change', function () {
                        table
                            .column( colIdx )
                            .search( this.value )
                            .draw();
                            //I tried to put my add table row code here but not working
                    } );
                } );
            });

Thanks for helping

This discussion has been closed.