const m = require('mithril');

const Pagination = require('../components/pagination');
const Datatable = require('../components/datatable');

const Datadisplay = module.exports = {};

Datadisplay.controller = function () {
  let ctrl = this;

  ctrl.currentPage = m.prop(m.route.param('page') || 1);
  ctrl.itemsPerPage = m.prop(10);
  ctrl.maxPage = m.prop(1);

  ctrl.setMaxPage = function (items) {
    ctrl.maxPage(Math.floor(items.length / ctrl.itemsPerPage() + 1));
    return items;
  };

  ctrl.paginate = function (items) {
    let count = parseInt(ctrl.itemsPerPage());
    let from = (parseInt(ctrl.currentPage()) - 1) * count;
    let to = from + count;
    return items.slice(from, to);
  };
};

Datadisplay.view = function (ctrl, args) {
  let data = args.data.then(ctrl.setMaxPage).then(ctrl.paginate);

  return m('div', [
    m.component(Pagination, {
      maxPage: ctrl.maxPage,
      currentPage: ctrl.currentPage
    }),
    m.component(Datatable, {
      columns: args.columns,
      names: args.names,
      data: data()
    })
  ]);
};
@@ -1037,16 +1037,119 @@
  data()%0A
+    %7D),%0A    m.component(Pagination, %7B%0A      maxPage: ctrl.maxPage,%0A      currentPage: ctrl.currentPage%0A
     %7D)%0A 

Add pagination to bottom of page too