how i can change html of td and tr after i get data by json

how i can change html of td and tr after i get data by json

pharmacypharmacy Posts: 1Questions: 0Answers: 0

hello

first of all this is my codes

HTML:

<table id="table_mydrug" class="table table-bordered table-striped sticky-header">
                <thead>
                <tr>
                  <th>Name</th>
                  <th>Scientific</th>
                  <th>Concentration</th>
                  <th>DosageForm</th>
                  <th>More Info</th>
                  <th>Sachet</th>
                  <th>Location</th>
                  <th>Quantity</th>
                  <th>Action</th>
                </tr>
                </thead>

              </table>

PHP:

$query="SELECT * FROM items  WHERE  slocation !=''";
$result=mysqli_query($db_conn, $query);


while($row = $result->fetch_array(MYSQLI_ASSOC)){

  $data[] = $row;

}


$results = ["sEcho" => 1,

          "iTotalRecords" => count($data),

          "iTotalDisplayRecords" => count($data),

          "aaData" => $data ];


echo json_encode($results);

Javascript:

        $(function () {
            $('#table_mydrug').DataTable({
                "bProcessing": true,
              "sAjaxSource": "test2.php",
               "aoColumns": [

                      { mData: 'name' } ,

                      { mData: 'scientific' },

                      { mData: 'concentration' },

                      { mData: 'dosageform' },

                      { mData: 'store' },

                      { mData: 'sachet' },

                      { mData: 'slocation' },

                      { mData: 'squantity' },

                      { mData: 'id' },

                    ],
              'paging'      : true,
              'lengthChange': false,
              'searching'   : true,
              'order'    : [],
              'info'        : true,
              'autoWidth'   : false,
            'bSortable' : false,
            'aTargets'  : [ 1 ],
            'lengthMenu': [100],
            })
          })

all its work 100%

my question is the html code dont have this tags:

<tbody>
<tr>
<td></td>
</tr>
</tbody>

so how i can edit html for this please ! because i need to edit the design of results after i get json data to my table!

hope you understand me!

Replies

  • colincolin Posts: 12,657Questions: 0Answers: 2,163

    There are a few ways you can go. You can modify cells with columns.render, or you can change how the rows are created with createdRow.

    Hopefully one of those will do the trick,

    Colin

Sign In or Register to comment.