DataTable

Organism

Server-side paginated data table. Card wrapper, başlık slotu, toolbar slotu, tıklanabilir satır ve her zaman görünür pagination desteği.

With title & pagination

Preview

Users

87 total

NameRoleStatusJoined
Alice JohnsonAdminActiveJan 2024
Bob SmithEditorActiveMar 2024
Carol WhiteViewerInactiveJun 2024
Dan BrownEditorPendingSep 2024

Showing 1–20 of 87

Code
<%- include('modules/ui/DataTable', {
  title: 'Users',
  subtitle: total + ' total',
  columns: [
    { key: 'name',   header: 'Name' },
    { key: 'role',   header: 'Role' },
    { key: 'status', header: 'Status' },
    { key: 'joined', header: 'Joined', align: 'right' },
  ],
  rows: users,
  page: page,       // current page (1-based), from req.query
  total: total,     // total record count, from DB
  pageSize: 20,
  qs: qs,           // query string without 'page', from route
}) %>

<%-- In your Express route: --%>
<%
  // const page = parseInt(req.query.page) || 1;
  // const { users, total } = await UserService.list({ page, pageSize: 20 });
  // const qs = new URLSearchParams(req.query); qs.delete('page');
  // res.render('users/index', { users, total, page, qs: qs.toString() });
%>

Clickable rows

Preview

Users

NameRoleStatusJoined
Alice JohnsonAdminActiveJan 2024
Bob SmithEditorActiveMar 2024
Carol WhiteViewerInactiveJun 2024
Dan BrownEditorPendingSep 2024

Showing 1–4 of 4

Code
<%- include('modules/ui/DataTable', {
  columns: [...],
  rows: users,
  page: page,
  total: total,
  pageSize: 20,
  qs: qs,
  getRowHref: function(row) { return '/users/' + row.userId; }
}) %>

Custom cell render

Preview
NameRoleStatusJoined
Alice JohnsonAdminActiveJan 2024
Bob SmithEditorActiveMar 2024
Carol WhiteViewerInactiveJun 2024
Dan BrownEditorPendingSep 2024

Showing 1–4 of 4

Code
<%- include('modules/ui/DataTable', {
  columns: [
    { key: 'name', header: 'User',
      render: function(row) {
        return '
' + '' + row.name.charAt(0).toUpperCase() + '' + '' + row.name + '' + '
'; } }, { key: 'status', header: 'Status', render: function(row) { var v = row.status === 'Active' ? 'bg-success-subtle text-success-fg' : row.status === 'Pending' ? 'bg-warning-subtle text-warning-fg' : 'bg-surface-overlay text-text-secondary'; return '' + row.status + ''; } }, ], rows: users, page: page, total: total, pageSize: 20, qs: qs, }) %>

Empty state

Preview

Users

NameRoleStatusJoined
No users found.

Showing 0–0 of 0

Code
<%- include('modules/ui/DataTable', {
  columns: [...],
  rows: [],
  page: 1,
  total: 0,
  pageSize: 20,
  qs: qs,
  emptyMessage: 'No users found.'
}) %>
Source modules/ui/DataTable.ejs