Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)29k · #9806

table-state

Skill này làm gì

Skill này giải thích cách theo dõi các thiết lập của bảng, như trang đang hiển thị, và cập nhật chúng trong trang Alpine.js. Skill dành cho lập trình viên cần bảng và phần còn lại của trang luôn khớp nhau.

Khi nào nên dùng

  • ✓Khi trang hiện tại hoặc một thiết lập khác của bảng cần được hiển thị trong nút hoặc nhãn.
  • ✓Khi bạn muốn điều khiển một phần trạng thái của bảng từ mã của mình.
  • ✓Khi bảng không cập nhật trên màn hình sau một thay đổi trạng thái.

Liên kết skill

https://github.com/TanStack/table/blob/main/packages/alpine-table/skills/table-state/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/TanStack/table/blob/main/packages/alpine-table/skills/table-state/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bảng Alpine.js của tôi không cập nhật số trang sau khi tôi bấm tiếp theo. Tôi sửa điều đó như thế nào?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chỉ cách truyền trạng thái được điều khiển bằng một getter và một callback, để Alpine đọc giá trị mới nhất và màn hình cập nhật khi nó thay đổi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Load intent load @tanstack/table-core#table-state first for shared ownership, initialization, updater, and reset rules.

Alpine's table proxy makes reads inside x-text, x-for, x-if, bound attributes, x-effect, and Alpine getters reactive. Event handlers read the current value when invoked. A captured value outside a binding does not become a continuing subscription, and there is no table.Subscribe component.

Controlled getter setup

<!-- skill-snippet:check -->
import Alpine from 'alpinejs'
import {
  createTable,
  rowPaginationFeature,
  tableFeatures,
  type PaginationState,
} from '@tanstack/alpine-table'

const features = tableFeatures({ rowPaginationFeature })
const columns = [{ accessorKey: 'name' }]
const data = [{ name: 'Ada' }]

Alpine.data('pagedTable', () => {
  const local = Alpine.reactive<{ pagination: PaginationState }>({
    pagination: { pageIndex: 0, pageSize: 10 },
  })
  const table = createTable({
    features,
    columns,
    data,
    state: {
      get pagination() {
        return local.pagination
      },
    },
    onPaginationChange: (next) => {
      local.pagination =
        typeof next === 'function' ? next(local.pagination) : next
    },
  })
  return { table }
})

Read table.atoms.pagination.get().pageIndex directly in an Alpine binding.

Reactive boundaries

  • A controlled slice needs a getter and callback. state: { pagination: local.pagination } captures the old object when the owner later replaces it.
  • Expose changing data through get data() and keep features, columns, and derived data stable outside reevaluated getters.
  • The proxy normally reevaluates all Table-reading bindings for every state change. A narrow atom read does not by itself narrow that broad invalidation.
  • For shared state, pass a stable external atom through atoms; omit controlled state and its callback for the same slice.

Read for the task

For advanced reactive boundaries, shared atoms, or detailed subscription examples, read reactivity. For construction or rendering setup, read getting-started.

API discovery

Inspect node_modules/@tanstack/alpine-table/dist/index.d.ts, createTable.d.ts, and reactivity.d.ts. Core feature APIs are in node_modules/@tanstack/table-core/dist/features/.

Câu hỏi thường gặp

Vì sao bảng không làm mới khi trạng thái thay đổi?

Thường dữ liệu hoặc trạng thái đã được sao chép một lần thay vì đọc qua getter, nên Alpine không thấy các thay đổi sau đó.

Tôi có thể đọc một giá trị một lần trong trình xử lý click không?

Có. Trình xử lý sự kiện đọc giá trị hiện tại tại thời điểm chúng chạy.

Điều này có thay thế hướng dẫn bảng cốt lõi không?

Không. Nó bổ sung các quy tắc riêng của Alpine lên trên các quy tắc sở hữu và đặt lại dùng chung trong hướng dẫn cốt lõi.

Chi tiết

Mô tả gốc của tác giả

Read and control Table v9 state in alpine. Use for tracked reads, subscriptions, controlled slices, and framework-specific reactive boundaries.

repo: TanStack/table

Độ phổ biến

Sao GitHub
29k
Vị trí xếp hạng
#9806
Giấy phép
MIT
Cập nhật
21/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự