Excuse me if the similar question has been already asked..
I'd like to create an HTML table with the following features:
- If
myFunctionreturns no result then it just shows the headers - from time to time
myFunctionreturns some data, that need to be displayed in this table - Table must be resizable, i.e. when we drag a window borders it consequently resizes its borders, without row/column reodering
Here is my current table:
<div id="result">
<table id="myTable" class="display" style="width:100%">
<tr>
<th>Header1</th>
<th>Header2</th>
<th>Header3</th>
</tr>
</table>
</div>
JavaScript:
function myFunction() {
$.ajax({
type: "GET",
url: 'some',
dataType: 'json',
data: parameters,
success: function (response) {
myTable.empty().show(); // to clear
// html table content calculation...
myTable.append(new html);
}
});
}
Every time I run myFunction I get table without headers, because of emptying of the variable.. but otherwise I don't understand how to update content dynamically without page reloading.. could you please assist?
<thead>and append an empty<tbody>after it. Then empty() thetbodyinstead of the entire table inmyFunction