0.1.7 • Published 5 months ago

@madulinux/react-datatable v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@madulinux/react-datatable

npm version MIT License

Reusable DataTable React component with sorting, paging, filtering, async fetch, and custom styling. Perfect for dynamic tables, admin panels, and filter integration.


Dokumentasi Indonesia


✨ Features

  • Column sorting (click header)
  • Pagination & perPage
  • Dynamic filtering (filterValues prop)
  • Async data fetch (API ready)
  • Custom cell/action rendering
  • Full styling via className props
  • TypeScript support

🚀 Installation

npm install @madulinux/react-datatable

🔥 Basic Usage

import DataTable from '@madulinux/react-datatable';

const columns = [
  { key: 'name', label: 'Name', sortable: true },
  { key: 'email', label: 'Email' },
  { key: 'status', label: 'Status', render: row => row.status ? 'Active' : 'Inactive' }
];

const fetchData = async ({ page, perPage, search }) => {
  const res = await fetch(`/api/users?page=${page}&perPage=${perPage}&search=${search}`);
  const data = await res.json();
  return { data: data.items, total: data.total };
};

<DataTable
  columns={columns}
  fetchData={fetchData}
  defaultPerPage={10}
/>

🧩 API & Props

PropTypeDescription
columnsArray<{ key, label, sortable?, render? }>Column definitions and cell rendering
fetchDatafunction(params) => Promise<{data,total}>Async data fetch (API, etc)
filterValuesobjectAdditional filters (optional)
defaultPerPagenumberItems per page (default: 10)
actionsfunction(row) => ReactNodeCustom action rendering per row
classNamestringStyling root container
tableClassNamestringStyling element
headerClassNamestringStyling all
rowClassNamestringStyling all
cellClassNamestringStyling all

🎨 Custom Styling

You can fully customize the appearance using className props:

<DataTable
  columns={columns}
  fetchData={fetchData}
  className="rounded-lg shadow bg-white"
  tableClassName="border"
  headerClassName="bg-gray-100 text-gray-700"
  rowClassName="hover:bg-gray-50"
  cellClassName="px-4 py-2 border-b"
/>
  • Use Tailwind, CSS modules, or global CSS as needed.
  • For dark mode, just add the appropriate className.

🛠️ Troubleshooting & Integration Notes

  • Make sure fetchData returns { data, total }.
  • Use className or custom styles for appearance.
  • For custom actions, use the actions prop.
  • For dynamic filtering, use the filterValues prop.

🤝 Contribution

Pull requests, suggestions, and issues are welcome! Fork the repo and submit a PR.

👤 Author

madulinux
GitHub
npmjs

License

MIT

Export & Column Visibility Lihat dokumentasi lengkap di repo atau DOCUMENTATION_SELECT2_DATATABLE.md

Lisensi

MIT

0.1.7

5 months ago

0.1.6

6 months ago

0.1.5

6 months ago

0.1.4

6 months ago

0.1.3

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago