Skip to content

Commit

Permalink
merging component
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguxx committed May 28, 2015
1 parent 54a4694 commit 4018d5f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
85 changes: 71 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,88 @@ Pagination file can be used with any common.js it is expect for [mithril](https:

```JavaScript

function list(data) {
return m('.ui.segment.sixteen.wide.column', [
m('ul.ui.bulleted.list', data.map(function (item) {
return m('li', {
key: item.id
}, item.name);
}))
]);
}

function table(data) {
return m('.ui.sixteen.wide.column', [
m('table.ui.table', [
m('tbody', data.map(function (item) {
return m('tr', {
key: item.id
}, [
m('td', item.id),
m('td', item.name)
]);
}))
])
]);
}

module.controller = function () {
pagination = new Pagination();
module.vm.init();
this.pagination = m.component(Pagination, {
data: module.vm.data,
rowsperpage: module.vm.rowsperpage,
pagerender: list,
wrapperclass: 'column'
});
this.paginationCtrl = new this.pagination.controller();
};

module.vm = {};
module.vm.init = function () {
this.data = array;
this.rowsperpage = 10;
this.page = m.prop(3);
};
function list(data) {
pagination.calculatePagination(data, module.vm.rowsperpage);
var cdata = data.slice(pagination.latest, pagination.rowsperpage * pagination.currentpage);
return cdata.map(function (item) {
return m('li', item.name);
});
}
module.view = function (/*ctrl*/) {
return m('.ui.grid.page', [


module.view = function (ctrl) {
return m('.ui.grid.page.one.column', [
m('h1', 'Pagination'),
m('.ui.segment.sixteen.wide.column', [
m('ul.ui.bulleted.list', list(array))
m.component(Pagination, {
data: module.vm.data,
rowsperpage: module.vm.rowsperpage,
pagerender: list,
wrapperclass: 'column',
page: module.vm.page
}),
m.component(Pagination, {
data: module.vm.data,
rowsperpage: module.vm.rowsperpage,
pagerender: table,
wrapperclass: 'column'
}),
m('.row', [
m('.column', [
m('br')
])
]),
pagination.buildPagination()
ctrl.pagination.view(ctrl.paginationCtrl),
m('.row', [
m('.column', [
m('button.ui.button', {
onclick: function () {
module.vm.data.splice(30, 10);
ctrl.paginationCtrl.goToPage(4);
module.vm.page(4);
}
}, 'go to page 3')
])
])
]);
};

m.module(window.document.body, module);
m.mount(window.document.body, module);

```

## Attributes
Expand All @@ -66,6 +120,9 @@ It accepts the following properties

* data, array of data to paginate
* rowsperpage, # of rows to show each page
* pagerender, page render function
* wrapperclass, class to add to parent div
* page, m.prop value of the current page
* class object map with:
* **activeClass**, applied to the active icons, defaults `active`
* **itemClass**, applied to non icon items, defaults `icon`
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sm-pagination",
"version": "0.0.5",
"version": "0.1.0",
"homepage": "https://github.com/pinguxx/sm-pagination",
"authors": [
"Ivan Torres <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.10.3/semantic.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mithril/0.1.33/mithril.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mithril/0.2.0/mithril.min.js"></script>
<script src="Pagination.js"></script>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sm-pagination",
"version": "0.0.5",
"version": "0.1.0",
"description": "mithril semantic-ui pagination widget",
"main": "Pagination.js",
"scripts": {
Expand Down
4 changes: 0 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
}

function list(data) {
//pagination.controller.calculatePagination(data, module.vm.rowsperpage);
//var cdata = data.slice(pagination.latest, pagination.rowsperpage * pagination.currentpage);
return m('.ui.segment.sixteen.wide.column', [
m('ul.ui.bulleted.list', data.map(function (item) {
return m('li', {
Expand All @@ -25,8 +23,6 @@
}

function table(data) {
//pagination2.calculatePagination(data, module.vm.rowsperpage);
//var cdata = data.slice(pagination2.latest, pagination2.rowsperpage * pagination2.currentpage);
return m('.ui.sixteen.wide.column', [
m('table.ui.table', [
m('tbody', data.map(function (item) {
Expand Down

0 comments on commit 4018d5f

Please sign in to comment.