npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lamlib/pagination

v1.1.0

Published

A library for tablur on client-side

Downloads

4

Readme

📚 Pagination.js

Pagination.js là thư viện JavaScript nhẹ giúp phân trang bảng dữ liệu HTML, hỗ trợ cả dữ liệu client-side và server-side, tìm kiếm, xuất Excel và UI hiện đại.


✨ Tính năng chính

  • 🔄 Phân trang động: Hỗ trợ dữ liệu phía client & server
  • 🔍 Tìm kiếm tức thời: Tìm kiếm theo từ khóa với debounce
  • 📤 Xuất Excel: Xuất bảng thành file .xlsx chỉ với một nút bấm
  • 🔢 Tùy chọn số dòng/trang: Dropdown thay đổi số dòng/trang
  • 📑 Chọn trang nhanh: Dropdown chọn trang (nếu bật)
  • 🧩 Tùy biến cao: Tùy chỉnh render dòng bảng (rowRenderer)
  • 🌐 Tích hợp đơn giản: Không phụ thuộc framework

🚀 Cài đặt

1. Chèn thư viện

<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script type="module" src="/path/to/pagination.js"></script>

💡 Sử dụng cơ bản

1. HTML cơ bản

<input type="text" id="search-box" placeholder="Tìm kiếm..." />
<table id="data-table">
    <thead>
        <tr>
            <th>#</th>
            <th>Tên</th>
            <th>Tuổi</th>
            <th>Địa chỉ</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>
<div id="pagination"></div>
<button id="export-btn">Xuất Excel</button>

2. Khởi tạo

import Pagination from './pagination.js';

const pag = new Pagination({
    tableId: 'data-table',
    paginationContainerId: 'pagination',
    searchInputId: 'search-box',
    exportButtonId: 'export-btn',
    itemsPerPage: 5,
    showItemsPerPageSelect: true,
    showPageSelect: true,
    isShowTotalSize: true,
    data: [
        { name: 'Nguyễn Văn A', age: 28, address: 'Hà Nội' },
        { name: 'Trần Thị B', age: 24, address: 'Đà Nẵng' },
        // ...
    ]
});

🌐 Phân trang server-side (tùy chọn)

const pag = new Pagination({
    serverCallback: (limit, offset, done) => {
        fetch(`/api/users?limit=${limit}&offset=${offset}`)
            .then(res => res.json())
            .then(({ data, total }) => {
                done(data, total); // Callback trả về data và tổng số bản ghi
            });
    },
    totalSize: 0, // sẽ được cập nhật tự động
    // ...
});

📤 Xuất Excel

  • Cần có thư viện SheetJS.
  • Dữ liệu xuất là dữ liệu đã được lọc và sắp xếp hiện tại.

🛠️ Tuỳ biến nâng cao

Tùy chỉnh render dòng

rowRenderer: (index, item) => `
    <tr>
        <td>${index + 1}</td>
        <td>${item.name}</td>
        <td>${item.age}</td>
        <td>${item.address}</td>
    </tr>
`

Sự kiện sau khi render

onRender: () => {
    console.log('Bảng đã được render lại');
}

🔧 API Configuration

| Option | Type | Default | Mô tả | |-------------------------|-----------|-----------------|---------------------------------------| | tableId | string | "data-table" | ID bảng HTML | | paginationContainerId | string | "pagination" | ID container cho phân trang | | searchInputId | string | "" | ID của input tìm kiếm | | exportButtonId | string | "" | ID nút xuất Excel | | itemsPerPage | number | 5 | Số dòng mỗi trang | | currentPage | number | 1 | Trang khởi tạo | | showItemsPerPageSelect| boolean | false | Dropdown chọn dòng/trang | | showPageSelect | boolean | false | Dropdown chọn trang | | isShowTotalSize | boolean | false | Hiển thị tổng bản ghi | | rowRenderer | function | Mặc định | Hàm render dòng | | data | array | [] | Dữ liệu đầu vào (client-side) | | serverCallback | function | null | Callback lấy dữ liệu từ server | | totalSize | number | 0 | Tổng số bản ghi (server-side) | | onRender | function | null | Gọi lại sau khi render xong |


🎯 Các tình huống sử dụng

  • ✅ Phân trang dữ liệu client nhỏ
  • 🌐 Tải dữ liệu phân trang từ server (REST API)
  • 📤 Tạo nút xuất Excel nhanh
  • 🔍 Thêm ô tìm kiếm ngay trên bảng

🧪 Ví dụ đầy đủ

new Pagination({
    tableId: 'data-table',
    paginationContainerId: 'pagination',
    searchInputId: 'search',
    exportButtonId: 'export-btn',
    showItemsPerPageSelect: true,
    showPageSelect: true,
    isShowTotalSize: true,
    itemsPerPage: 10,
    data: danhSachNguoiDung, // mảng object
    onRender: () => {
        console.log('Render xong!');
    }
});

🪪 License

MIT License © 2025