I am using https://markcell.github.io/jquery-tabledit/. It works perfectly when I have the datatable with PHP.
However when I do the same with AJAX, the datatable is not recognized (functionalities doesn't work)
I was wondering if it could be any workaround to get this work or is it in general when you fetch you cant use it with javascript after its fetched?
I am also open for any suggestion for a live editable datatable library
Thank you
$(document).ready(function() {
fetch_orderdetails()
function fetch_orderdetails() {
$.ajax({
url: "/api/v1/orders/1",
dataType: "json",
success: function(orderdetails) {
var html = '';
for (var count = 0; count < orderdetails.length; count++) {
alert(orderdetails[count].coincode);
html += '<tr style="text-align:center!important;">';
html += '<td style="display:none;">' + orderdetails[count].id + '</td>';
html += '<td>' + orderdetails[count].jeton + '</td>';
html += '<td>' + orderdetails[count].triggerpricebuy + '</td>';
html += '<td>' + orderdetails[count].triggerpricesell + '</td>';
html += '<td>' + orderdetails[count].availableusd + '</td>';
html += '<td>Action</td>';
html += '<td>' + orderdetails[count].coincode + '</td>';
html += '</tr>';
}
$('tbody#orderdetails').html(html);
}
});
}
});
<div class="row">
<div class="col-xl-9 col-lg-12">
<div class="table-responsive text-white table-hover fs-14" style="">
@csrf
<table id="editable" class="table table-striped display mb-4 dataTablesCard short-one card-table text-black" style="font-size:1.1rem; text-align:center!important; color:white!important;">
<thead style="font-size:1.5rem!important;">
<tr>
<th style="display:none!important;">id</th>
<th style="padding-left: 0px!important; padding-right:0px!important;">Jeton</th>
<th>BuyPrice</th>
<th>SellPrice</th>
<th>$ Value</th>
<th>Actions</th>
<th>OrderType</th>
</tr>
</thead>
<tbody id="orderdetails">
// For non-Ajax version only difference I have a foreach loop here with the same source with same classes and other details.
</tbody>
</table>
</div>
</div>
My Answer:
= orderdetails.length; count++) {_ html += '
To solve this issue, you can initialize the TableEdit plugin after the AJAX call is successful. Here's an updated version of your code:
javascript
$(document).ready(function() {
fetch_orderdetails();
function fetch_orderdetails() {
$.ajax({
url: "/api/v1/orders/1",
dataType: "json",
success: function(orderdetails) {
var html = '';
for (var count = 0; count < orderdetails.length; count++) {
html += ''
html += '' + orderdetails[count].id + ' '
html += '' + orderdetails[count].product_name + ' '
html += '' + orderdetails[count].quantity + ' '
html += ' '
}
$('#orderdetails_table').html(html);
// Initialize TableEdit plugin after populating the table
$('#orderdetails_table').Tabledit({
// Specify options for the plugin here
});
}
});
}
});
By initializing the TableEdit plugin after populating the table with data, the functionalities of the plugin should work as expected. Make sure to replace `#orderdetails_table` with the actual ID of your table element.
If you are looking for alternative live editable datatable libraries, you can consider libraries like DataTables (https://datatables.net/) or Handsontable (https://handsontable.com/). These libraries provide similar functionalities for live editing of data tables.
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Rate this post
5 of 5 based on 3235 votesComments