Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82034

How to initialize datatable created as html dom in other file and appended in div using ajax?

$
0
0

DataTable is just like a miracle for newbies like me.
i have created data table like this in one file

$db = new Database(); /
$output = '';
$result = $db->conn->query($query);

  //provide the query which we get from action file to db class and store result in $result variable
       $output .= '
       <table id ="user_table1" class="table table-bordered table-striped">
            <tr>

                 <th width="35%">Voucher # </th>
                 <th width="35%">Date</th>
                 <th width="35%">Amount</th>

                 <th width="5%">Print</th>
                 <th width="5%">Edit</th>
                 <th width="5%">View</th>
                 <th width="5%">Delete</th>

            </tr>
       ';


       while($row = mysqli_fetch_object($result))
       {
            $output .= '
            <tr>

                 <td>'.$row->vnum.'</td>
                 <td>'.$row->date.'</td>
                 <td>'.$row->total.'</td>
                  <td><button type="button" name="print" id="'.$row->vnum.'" class="btn btn-warning btn-sm print_data" >Print</button></td>
                 <td><button type="button" name="update" id="'.$row->vnum.'" class="btn btn-success btn-sm edit_data" >Update</button></td>
                 <td><button type="button" name="view" id="'.$row->vnum.'" class="btn btn-info btn-sm view_data">View</button></td>
                 <td><button type="button" name="Delete" id="'.$row->vnum.'" class="btn btn-danger btn-sm delete_data" >Delete</button></td>

            </tr>
            ';
       }


       $output .= '</table>';
       return $output;

now i get this in main file using ajax method and appending it as innerhtml in a div container.
now i want to initialize datatable functions on this table .
How to do that?


Viewing all articles
Browse latest Browse all 82034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>