vanng822 / pagination Goto Github PK
View Code? Open in Web Editor NEWPagination for javascript and nodejs
License: MIT License
Pagination for javascript and nodejs
License: MIT License
If you parse the current page as a string, the previous button will work correctly as its doing a minus operation. But the next button does a plus, so it does a string concat.
I know this isn't a bug, as the user should always pass an integer, but I can see people having problems. For example people using express and getting the page parameter will get it as a string, and if they pass that straight to the pagination, it will half work.
Is a parseInt a good idea? Or highlighting it in the docs to remember to pass integers. It'll save people a few minutes I'm sure.
Thanks for the module.
there is no way to customize html templates
For example - getting compatible with bootstrap markap
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">«</a></li>
<li><a href="#">«</a></li>
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
</ul>
I'm rendering my page using ejs.
app.get('/music_mp3', function (req, res) {
var collection = db.get().collection('sc_music_mp3');
var num_pages = parseInt(em.data.sc_music_mp3_count / 20) + (em.data.sc_music_mp3_count % 20 ? 1 : 0);
console.log(num_pages);
collection.find().limit(20).toArray(function (err, docs) {
var bstrapPaginator = new pagination.TemplatePaginator({
prelink: '/music_mp3',
current: 1,
rowsPerPage: 5,
totalResult: em.data.sc_music_mp3_count,
slashSeparator: true,
template: function (result) {
var i, len, prelink;
var html = "<div><ul class='pagination'>";
if (result.pageCount < 2) {
html += "</ul></div>";
return html;
}
prelink = this.preparePreLink(result.prelink);
if (result.previous) {
html += '<li><a href="' + prelink + result.previous + '">' + this.options.translator('PREVIOUS') + '</a></li>';
}
if (result.range.length) {
for (i = 0, len = result.range.length; i < len; i++) {
if (result.range[i] === result.current) {
html += '<li class="active"><a href="' + prelink + result.range[i] + '">' + result.range[i] + '</a></li>';
} else {
html += '<li><a href="' + prelink + result.range[i] + '">' + result.range[i] + '</a></li>';
}
}
}
if (result.next) {
html += '<li><a href="' + prelink + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a></li>';
}
html += '</ul></div>';
return html;
}
});
var rendered_pagination = bstrapPaginator.render();
// ejs page rendering
res.render('pages/music_mp3', {
songs: docs,
paginator: rendered_pagination
});
console.log("Songs Loaded... UI updated");
});
});
But this converts all the tags into html entities.
<nav>
<div><ul class='pagination'><li class="active"><a href="/music_mp3/page/1">1</a></li><li><a href="/music_mp3/page/2">2</a></li><li><a href="/music_mp3/page/3">3</a></li><li><a href="/music_mp3/page/4">4</a></li><li><a href="/music_mp3/page/5">5</a></li><li><a href="/music_mp3/page/2" class="paginator-next">Next</a></li></ul></div>
</nav>
What am I doing wrong?
We need only those in browser then better having it in other file and build with it. When running in node we don't need those.
To get better user experience (for repo users) I recommend to host example directory on gh-pages.
I think that way increase users of this package/repo
Hello,
what is difference in search and item paginator?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.