Hello!
I would like to implement a datatable from HTML version ( with subtable ) in Laravel version using Yajra Laravel described here:
https://preview.keenthemes.com/metronic8/laravel/documentation/general/datatables/overview?demo=demo1
This is the table: https://preview.keenthemes.com/html/metronic/docs/general/datatables/subtable
Everything is working just fine, but I need some help in adding the row for the subtable to the actual table at initialization. I basically need to add this code to the table and don't know how:
<!--begin::SubTable template-->
<tr data-kt-docs-datatable-subtable="subtable_template" class="d-none">
<td colspan="2">
<div class="d-flex align-items-center gap-3">
<a href="#%22%20class=%22symbol%20symbol-50px%20bg-secondary%20bg-opacity-25%20rounded" target="_blank" rel="noopener noreferrer">
<img src="/assets/media/stock/ecommerce/" alt="" data-kt-docs-datatable-subtable="template_image" />
</a>
<div class="d-flex flex-column text-muted">
<a href="#%22%20class=%22text-dark%20text-hover-primary%20fw-bold%22%20data-kt-docs-datatable-subtable=%22template_name" target="_blank" rel="noopener noreferrer">Product name</a>
<div class="fs-7" data-kt-docs-datatable-subtable="template_description">Product description</div>
</div>
</div>
</td>
<td class="text-end">
<div class="text-dark fs-7">Cost</div>
<div class="text-muted fs-7 fw-bold" data-kt-docs-datatable-subtable="template_cost">1</div>
</td>
<td class="text-end">
<div class="text-dark fs-7">Qty</div>
<div class="text-muted fs-7 fw-bold" data-kt-docs-datatable-subtable="template_qty">1</div>
</td>
<td class="text-end">
<div class="text-dark fs-7">Total</div>
<div class="text-muted fs-7 fw-bold" data-kt-docs-datatable-subtable="template_total">name</div>
</td>
<td class="text-end">
<div class="text-dark fs-7 me-3">On hand</div>
<div class="text-muted fs-7 fw-bold" data-kt-docs-datatable-subtable="template_stock">32</div>
</td>
<td></td>
</tr>
<!--end::SubTable template-->
Hi Dumitrescu Daniel
Instead of adding a table row as HTML codes, you can add it via the data. Append a new data row and then reload the table.
You can do it using js.
https://datatables.net/examples/api/add_row.html
Or append the data in the query()
function in the datatable initialization file.
Thanks