Position DataTable inside Bootstrap4 card and have pagination outside of card
Position DataTable inside Bootstrap4 card and have pagination outside of card
oSIRus
Posts: 5Questions: 2Answers: 0
Hey all,
I'm trying to position a dataTable inside a Bootstrap4 card-body (which is already working fine) but I want to have the pagination for that dataTable outside (below) the card.
I could only come up with the following which is sadly not working:
$('#searchResultsTable').DataTable({
"dom": '<"upperCardHtml">t<"lowerCardHtml">p',
} );
$("div.upperCardHtml").html("<div class='col-7'><div class='card'><div class='card-header'><span data-feather='align-left' style='margin-bottom: 2px;'></span> &{'common.search.results'}</div><div class='card-body m-0 p-0'>");
$("div.lowerCardHtml").html("</div></div>");
Can someone please give me a hint?
Thank you!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
you may have a timing issue where you are trying to append to the div before its done being created.
Use preInit event handler to ensure its there before you append the html. It would look like
as seen here: http://live.datatables.net/menokuja/1/edit
Thanks for the reply, but i get exactly the same results using the preInit event handler.
Ok, now I did it different, it looks ok now with this code:
Pagination is the div where I want my pagination to be displayed.
BUT:
Pagination shows in my pagination div but clicking on page 2 for example doesn't do anything. The pagination just doesn't react.
That is because you are copying the html but not the event handlers that go with it.
Try something like
$("#searchResultsTable_paginate").appendTo("#pagination");
It's working! Thank you very much!