Tailwind CSS Academy · Pelajaran

Tabel Data dan Placeholder Grafik

Bangun tabel data yang tampak dapat diurutkan dengan baris bergaris, tombol tindakan, dan kontrol paginasi, serta wadah grafik placeholder dengan pemuat kerangka.

Pelajaran 4 dari 413 langkah

Tabel Data dan Placeholder Grafik adalah pelajaran Tailwind CSS Academy gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Tailwind CSS Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Tailwind CSS Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Data Table Role in Dashboards

Data tables are one of the most common components in admin dashboards. They display structured records — users, orders, transactions — in rows and columns, often with sorting, filtering, and pagination controls. A well-styled Tailwind table is readable, scannable, and interactive. The table is typically placed below the stat cards in the main content area.

Table Container and Wrapper

Wrap the table in a rounded-xl bg-white shadow-sm overflow-hidden card container. The overflow-hidden clips the table corners to match the card's border radius. Inside the card, add a table header with the table title and action buttons, followed by an overflow-x-auto div that allows horizontal scrolling on mobile without breaking the layout.

<div class="rounded-xl bg-white shadow-sm overflow-hidden">
  <!-- Table header bar -->
  <div class="flex items-center justify-between border-b border-gray-100 px-6 py-4">
    <h3 class="font-semibold text-gray-900">Recent Users</h3>
    <button class="text-sm font-medium text-blue-600 hover:text-blue-700">View all</button>
  </div>
  <!-- Scrollable table -->
  <div class="overflow-x-auto">
    <table class="w-full text-sm">
      <!-- thead and tbody -->
    </table>
  </div>
</div>

Table Header Row

The thead contains column labels. Use bg-gray-50 for the header row background to visually distinguish it from data rows. Each th gets px-6 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 — a classic small-caps header style that is compact and professional.

<thead class="bg-gray-50">
  <tr>
    <th scope="col"
        class="px-6 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
      Name
    </th>
    <th scope="col"
        class="px-6 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
      Email
    </th>
    <th scope="col"
        class="px-6 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
      Status
    </th>
    <th scope="col"
        class="px-6 py-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500">
      Role
    </th>
    <th scope="col" class="relative px-6 py-3"><span class="sr-only">Actions</span></th>
  </tr>
</thead>

Striped Table Rows

Alternating row colors (striped rows) improve readability in dense tables by making it easy to track a row across columns. In Tailwind, use the even:bg-gray-50 variant on tr elements to color even rows and leave odd rows white. Add hover:bg-blue-50 transition-colors for a hover highlight that helps users identify the row under their cursor.

<tbody class="divide-y divide-gray-100 bg-white">
  <tr class="even:bg-gray-50 hover:bg-blue-50 transition-colors">
    <td class="whitespace-nowrap px-6 py-4">
      <div class="flex items-center gap-3">
        <img src="/avatar.jpg" class="h-8 w-8 rounded-full" alt="">
        <div>
          <p class="font-medium text-gray-900">Alice Johnson</p>
          <p class="text-xs text-gray-500">Joined Jan 2026</p>
        </div>
      </div>
    </td>
    <td class="whitespace-nowrap px-6 py-4 text-gray-500">alice@example.com</td>
    <!-- More cells -->
  </tr>
</tbody>

Status Badge in Table Cells

Status columns use small colored badges to communicate state at a glance. Define three or four status variants: Active (green), Inactive (gray), Pending (yellow), Suspended (red). Each badge uses inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold with color-appropriate background and text classes applied conditionally based on the status value.

<td class="whitespace-nowrap px-6 py-4">
  <!-- Active -->
  <span class="inline-flex items-center rounded-full bg-green-100 px-2.5 py-0.5
               text-xs font-semibold text-green-800">
    Active
  </span>

  <!-- Pending -->
  <span class="inline-flex items-center rounded-full bg-yellow-100 px-2.5 py-0.5
               text-xs font-semibold text-yellow-800">
    Pending
  </span>

  <!-- Suspended -->
  <span class="inline-flex items-center rounded-full bg-red-100 px-2.5 py-0.5
               text-xs font-semibold text-red-800">
    Suspended
  </span>
</td>

Table Action Buttons

The last column of each row contains row-level actions: Edit, Delete, or View. Align these with text-right on the th and td. Use text-only buttons styled as links to keep the table clean: text-sm font-medium text-blue-600 hover:text-blue-700 for Edit and text-red-500 hover:text-red-700 for Delete. Separate them with a light divider: mx-3 text-gray-300.

<td class="whitespace-nowrap px-6 py-4 text-right">
  <a href="/users/1/edit"
     class="text-sm font-medium text-blue-600 hover:text-blue-700">
    Edit
  </a>
  <span class="mx-2 text-gray-300">|</span>
  <button onclick="deleteUser(1)"
          class="text-sm font-medium text-red-500 hover:text-red-700">
    Delete
  </button>
</td>

Pagination Controls

Pagination controls sit below the table. A common pattern shows Showing 1 to 10 of 48 results on the left and Previous/Next buttons on the right. Use flex items-center justify-between border-t border-gray-100 px-6 py-4 for the pagination bar container, keeping it visually attached to the table above it.

<div class="flex items-center justify-between border-t border-gray-100 px-6 py-4">
  <p class="text-sm text-gray-500">
    Showing <span class="font-medium">1</span> to <span class="font-medium">10</span>
    of <span class="font-medium">48</span> results
  </p>
  <div class="flex gap-2">
    <button class="rounded-lg border border-gray-300 px-3 py-1.5 text-sm
                   font-medium text-gray-700 transition hover:bg-gray-50
                   disabled:cursor-not-allowed disabled:opacity-40"
            disabled>
      Previous
    </button>
    <button class="rounded-lg border border-gray-300 px-3 py-1.5 text-sm
                   font-medium text-gray-700 transition hover:bg-gray-50">
      Next
    </button>
  </div>
</div>

Chart Placeholder Container

Chart placeholder widgets provide the correct layout and skeleton structure for where a chart library (like Chart.js or Recharts) will render. The placeholder card has a header with the chart title and time period selector, a large content area with fixed height for the chart canvas, and optional legend items below. Using placeholders ensures the dashboard layout is stable before chart data loads.

<div class="rounded-xl bg-white shadow-sm">
  <!-- Chart header -->
  <div class="flex items-center justify-between border-b border-gray-100 px-6 py-4">
    <h3 class="font-semibold text-gray-900">Revenue Over Time</h3>
    <select class="rounded-lg border border-gray-200 px-3 py-1.5 text-sm text-gray-600">
      <option>Last 7 days</option>
      <option>Last 30 days</option>
      <option>Last 90 days</option>
    </select>
  </div>
  <!-- Chart canvas area -->
  <div class="h-64 p-6">
    <!-- Chart.js or Recharts renders here -->
    <canvas id="revenue-chart"></canvas>
  </div>
</div>

Skeleton Chart Placeholder

Before chart data loads, show a skeleton placeholder that mimics the chart's shape. For a bar chart placeholder, use a flex row of bars with animate-pulse. For a line chart, a simple rectangle with rounded corners and animate-pulse works. This prevents the jarring appearance of an empty white box before the chart library initializes.

<!-- Bar chart skeleton -->
<div class="flex h-52 items-end gap-2 animate-pulse">
  <div class="flex-1 rounded-t bg-gray-200" style="height: 60%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 80%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 45%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 90%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 70%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 55%"></div>
  <div class="flex-1 rounded-t bg-gray-200" style="height: 75%"></div>
</div>

Side-by-Side Chart and Table Layout

A common dashboard grid places a chart widget and a table (or secondary stat) side by side. Use a two-column grid: grid grid-cols-1 gap-6 lg:grid-cols-2. The chart and table fill equal columns. You can also use lg:col-span-2 to let one widget span the full width while smaller widgets occupy a third column in a 3-column sub-grid.

<!-- Main dashboard grid: chart + top-users table -->
<div class="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-3">
  <!-- Line chart (2/3 width) -->
  <div class="rounded-xl bg-white shadow-sm lg:col-span-2">
    <!-- Chart content -->
  </div>

  <!-- Top users list (1/3 width) -->
  <div class="rounded-xl bg-white shadow-sm">
    <!-- Mini leaderboard -->
  </div>
</div>

Empty State for Tables

When a table has no data — perhaps filtered to zero results or on a fresh account — show a centered empty state inside the table body. Use a flex column with an icon, a heading, a description, and a CTA button. Avoid showing an empty white box with no context, which disorients users who do not know if the page is broken or simply empty.

<!-- Empty state inside a table or list container -->
<div class="flex flex-col items-center justify-center py-16 text-center">
  <svg class="h-12 w-12 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
          d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0H4"/>
  </svg>
  <h3 class="mt-4 font-semibold text-gray-900">No users found</h3>
  <p class="mt-1 text-sm text-gray-500">Get started by adding your first team member.</p>
  <button class="mt-6 rounded-lg bg-blue-600 px-4 py-2 text-sm font-semibold text-white">
    Add user
  </button>
</div>

Quick Check

Test your understanding of Tailwind CSS Mastery concepts from this lesson.

Lesson Recap

In this lesson you learned: building a styled data table with striped rows, status badges, and action buttons, adding pagination controls with disabled states, and creating chart placeholder containers with skeleton loaders and empty states. Next up we explore CSS architecture and file organization with Tailwind.

Gratis untuk memulai

Belajar HTML dengan tutor AI — gratis

Tulis dan jalankan kode asli di browser kamu, dapatkan bantuan instan dari tutor AI 24/7, dan lanjutkan di mana kamu tinggalkan di web atau aplikasi.

Kursus
30
Pelajaran
120

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Tabel Data dan Placeholder Grafik” gratis?

Ya — teks lengkap “Tabel Data dan Placeholder Grafik” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Tailwind CSS Academy, upgrade ke CoddyKit PRO. Kursus Tailwind CSS Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Tabel Data dan Placeholder Grafik”?

Bangun tabel data yang tampak dapat diurutkan dengan baris bergaris, tombol tindakan, dan kontrol paginasi, serta wadah grafik placeholder dengan pemuat kerangka. Kamu berlatih Tailwind CSS Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Tailwind CSS Academy?

Tidak diperlukan pengalaman sebelumnya. Tailwind CSS Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Tabel Data dan Placeholder Grafik” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Tailwind CSS Academy ini?

Ya. Setiap pelajaran Tailwind CSS Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Kerangka Dasbor dan Bilah Samping
  2. Bilah Atas dan Breadcrumb
  3. Kartu Statistik dan Widget KPI
  4. Tabel Data dan Placeholder Grafik
← Kembali ke Tailwind CSS Academy