Когда я нажимаю на click1 (с идентификатором btn1), я вижу таблицу и все хорошо, но когда я нажимаю на нее снова, я получаю ошибку во всплывающем окне:
DataTables warning: table id=tableId - Cannot reinitialise DataTable. For more information about this
error, please see http://datatables.net/tn/3
это одна проблема.
после того, как, если я нажму на click2 (с идентификатором btn2), он откроется под первой таблицей, как я могу щелкнуть только 1 показом таблицы?
моя цель - переходить между таблицами, нажимая кнопки ,
спасибо!
мой код находится в Index.cs html (и я получаю правильный ответ от API):
<button id="btn1">Click1</button>
<button id="btn2">Click2</button>
<div class="container">
<table id="tableId" class="uk-table uk-table-hover uk-table-striped" style="width:100%">
</table>
</div>
<div class="container">
<table id="tableId2" class="uk-table uk-table-hover uk-table-striped" style="width:100%">
</table>
</div>
@section Scripts{
/*here all scripts and js files from cdn*/
<script>
$("#btn1").click(function () {
$.ajax("/api/TestNews/",
{ method: "get" })
.then(function (response) { // get the response (json data)
// console.dir(response);
$('#tableId') // take the id from table tag
.dataTable({
data: response, // the data of this table
columns: [
{ "data": "id", "title": "Id" },
{ "data": "domain", "title": "Domain" },
{ "data": "name", "title": "Name" },
],
className: 'mdl-data-table__cell--non-numeric'
});
});
});
$("#btn2").click(function () {
$.ajax("/api/TestNews/",
{ method: "get" })
.then(function (response) { // get the response (json data)
// console.dir(response);
$('#tableId2') // take the id from table tag
.dataTable({
data: response, // the data of this table
columns: [
{ "data": "id", "title": "Id" },
{ "data": "domain", "title": "Domain" },
{ "data": "name", "title": "Name" },
],
className: 'mdl-data-table__cell--non-numeric'
});
});
});
</script>
}