Git Product home page Git Product logo

pagination's Issues

Parsing integer as string causes differing results

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.

Markup customization

there is no way to customize html templates
For example - getting compatible with bootstrap markap

<ul class="pagination">
    <li><a href="#">&laquo;</a></li>
    <li><a href="#">&laquo;</a></li>
    <li><a href="#">&laquo;</a></li>
    <li><a href="#">&laquo;</a></li>
    <li><a href="#">1</a></li>
</ul>

Compiled template converts all the html tags into html entities while rendering on client side.

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>
                                &lt;div&gt;&lt;ul class=&#39;pagination&#39;&gt;&lt;li class=&quot;active&quot;&gt;&lt;a href=&quot;/music_mp3/page/1&quot;&gt;1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;/music_mp3/page/2&quot;&gt;2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;/music_mp3/page/3&quot;&gt;3&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;/music_mp3/page/4&quot;&gt;4&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;/music_mp3/page/5&quot;&gt;5&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;/music_mp3/page/2&quot; class=&quot;paginator-next&quot;&gt;Next&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;
</nav>

What am I doing wrong?

Host example pages on gh-pages

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.