simple-datatables icon indicating copy to clipboard operation
simple-datatables copied to clipboard

How to add custom CSS classes to pagination

Open coliff opened this issue 4 years ago • 2 comments

I'd like to use Simple-DataTables with Bootstrap 5 CSS without rewriting any CSS classes. Is it possible to add CSS class names to the existing classes at run-time?

https://getbootstrap.com/docs/5.1/components/pagination/

For Bootstrap's pagination that'd mean adding the class pagination to dataTable-pagination-list and then page-item to each li and page-link to each a.

coliff avatar Nov 30 '21 12:11 coliff

Answering my own question, I added this code for now, but keen to know if there is a better way:

document.addEventListener("DOMContentLoaded", function () {
  const ul = document.querySelector(".dataTable-pagination-list");
  ul.className = "pagination";

  var pageItem = document.querySelectorAll(".dataTable-pagination > ul > li");
  for (var i = 0; i < pageItem.length; i++) {
    pageItem[i].classList.add("page-item");
  }

  var pageLink = document.querySelectorAll(".dataTable-pagination > ul > li > a");
  for (var i = 0; i < pageLink.length; i++) {
    pageLink[i].classList.add("page-link");
  }
});

coliff avatar Nov 30 '21 13:11 coliff

@coliff - your approach looks good to me. If I were implementing something like this then I'd essentially take your code and plug it into a custom plugin.

dday9 avatar Mar 21 '22 18:03 dday9

If there is interest in it, we can make the class names configurable. This is already the case for the editing plugin.

johanneswilm avatar Jan 11 '23 08:01 johanneswilm

If there is interest in it, we can make the class names configurable. This is already the case for the editing plugin.

YES PLEASE! That would be awesome. The 'solution' code I posted above doesn't actually work well at all beacuse the class names are lost when the DOM is reloaded. Using custom class names configured would be very helpful.

coliff avatar Jan 11 '23 08:01 coliff

@coliff ok, this has now been added to [email protected]

johanneswilm avatar Jan 11 '23 09:01 johanneswilm