Skip to content

Commit

Permalink
Fix initialise() when it is called on empty data-table (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjchirag7 authored Apr 7, 2020
1 parent 8b9bfc8 commit b305d14
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions apps/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ <h5 class="modal-title" id="deleteModalLabel">Delete confirmation</h5>
if (data.length == 0) {
var div = document.querySelector('.container');
div.textContent = `No Data Found ... x _ x`;
div.classList = `text-center p-4`;
div.classList = `container text-center p-4`;
return;
}

Expand All @@ -410,11 +410,38 @@ <h5 class="modal-title" id="deleteModalLabel">Delete confirmation</h5>
tbody = data.map((d) => {
return "<tr>" + d.map((a) => "<td>" + a + "</td>").reduce((a, b) => a + b) + "</tr>";
});
totaltablepages = Math.ceil(data.length/$("#entries").val());
let entriesPerPage;
if($('#entries').val()===undefined)
entriesPerPage=10; // default value, when initially no slide
else
entriesPerPage= $('#entries').val();
totaltablepages = Math.ceil(data.length/entriesPerPage);
selectedpage = 0;
$("#search-table").val("");
searching = false;

if( data.length>0 && $('.container').children().length===0)
{
$('.container').html(`<div>
<div>
<h3 class="text-center h3 mb-0">Available Slides</h3>
<div class="search-box float-left form-group form-inline">
<select id='entries' class="select form-control mr-2">
<option value="10" selected>10 slides/page</option>
<option value="20">20 slides/page</option>
<option value="40">40 slides/page</option>
<option value="50">50 slides/page</option>
<option value="100">100 slides/page</option>
</select>
<input id="search-table" type="text" class="form-control" placeholder="Search&hellip;">
</div>
</div>
<div class="table-responsive">
<table id='datatables' class="table table-striped"></table>
</div>
</div >
`);
}
document.getElementById("datatables").innerHTML = `
<thead>${thead.reduce((a, b) => a + b)}</thead>
<tbody>${tbody.reduce((a, b) => a + b)}</tbody>
Expand Down

0 comments on commit b305d14

Please sign in to comment.