Sunday, 11 October 2015

Simple Pagination With jQuery



    jQuery(document).ready(function () {
                    var st = 0;
                    var ed = 0;
                    var cnt = 10;
                    var tAg = '.companyinfo div.result-body';

                    hideShow(0, cnt, '', tAg);

                    jQuery('.nextData').click(function () {
                        st = parseInt(st + cnt);
                        ed = parseInt(st + cnt);
                        //alert(ed);
                        jQuery(tAg).hide();
                        jQuery('.prevData').show();
                        hideShow(st, ed, cnt, tAg);
                    });

                    jQuery('.prevData').click(function () {
                        st = st - cnt;
                        ed = ed - cnt;
                        //alert(ed);
                        jQuery('.nextData').show();
                        jQuery(tAg).hide();
                        hideShow(st, ed, cnt, tAg);
                    });
                    /* Pagination End */

                    function hideShow(st, ed, rcrds, tAg) {
                        jQuery(tAg).hide();
                        if (st >= 10)
                        {
                            jQuery('.prevData').show();
                        } else
                        {
                            jQuery('.prevData').hide();
                        }
                        //Count Number of Div
                        var len = jQuery(tAg).size();
                        if (len - st <= rcrds || len < ed) {
                            jQuery('.nextData').hide();
                        }
                        //alert(st + 'p' + ed);
                        jQuery(tAg).slice(st, ed).each(function () {
                            jQuery(this).show();
                        });
                    }
                });
                /*                     * * Pagination End * */


No comments:

Post a Comment