Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Collections

  • QuestionCard
  • Table
  • Book3D
  • ProTable
  • PricingTable
  • JsonViewer
  • EditableTable
  • List
  • Descriptions
  • RowActions
  • Tree
  • Card
  • Carousel
  • Video
  • Audio
  • BentoGrid
  • Image
  • MagicCard
  • AnimatedList
  • Marquee
  • Sortable
  • Kanban
  • DesignCanvas
  • LayerTree
  • StageDraw
  • SlideDeck
  • PresenterView
  • ComponentPicker
  • EventStream
  • QueueLane
  • DocumentSheet
  • Novel reader
  • Scheduler
  • Org classroom
  • Danmaku
  • LiveChat
  • LivePlayer
  • LogViewer
  • FileTree
  • CodeReviewThread
  • VirtualList
  • InfiniteScroll
  • LogoLoop
  • BounceCards
  • CardSwap
  • ChromaGrid
  • CircularGallery
  • DomeGallery
  • FlyingPosters
  • InfiniteMenu
  • MagicBento
  • ScrollStack
  • ProfileCard
  • TiltedCard
  • PixelCard
  • DecayCard
  • ReflectiveCard
  • Folder

Charts and Diagrams

  • Flow
  • Diagram
  • Paper
  • SequenceDiagram
  • Sankey
  • Sparkline
  • Funnel
  • Treemap
  • Gantt
  • Heatmap
  • ContributionGraph
  • Legend
  • Chart
  • WorldMap

Information

  • ImageViewer
  • LiveProductCard
  • DiffStat
  • ScoreRing
  • ScoreScale
  • Badge
  • Dot
  • StatusDot
  • Chip
  • FilterChip
  • Coupon
  • Tag
  • Annotation
  • Avatar
  • AvatarCircles
  • User
  • QRCode
  • Comment
  • RelativeTime
  • GitCommit
  • DeployStatus
  • ShieldBadge
  • AwardBadge
  • CreditCard
  • IconTile

Metrics

  • Stat
  • Statistic
  • Meter
  • Timeline
  • NumberTicker

Placeholders

  • Empty
  • Skeleton
  • Watermark

EditableTable

editable-table

Edits validated row and cell values directly within a data table.

Usage

Inline editing · Add and delete lines

Click the editable column to enter the editing state, editor customizes the cell editor (drop-down/number); addable + newRow adds rows, deletable deletes rows; onChange returns complete new data.

NameRoleMonthly salaryActions
Zhang SanAdministrator¥24,000
Li SiEdit¥16,000
Wang WuGuest¥12,000
tsx
const [data, setData] = useState(rows);
const columns: EditableColumn<Row>[] = [
  { key: "name", title: "Name", editable: true, width: 160 },
  {
    key: "role", title: "Character", editable: true,
    render: (v) => <Tag tone="brand">{ROLE_LABEL[v]}</Tag>,
    editor: (value, onChange) => (
      <select value={value} onChange={(e) => onChange(e.target.value)}>
        {/* options… */}
      </select>
    ),
  },
  {
    key: "salary", title: "Monthly salary", editable: true, align: "right",
    render: (v) => `¥${Number(v).toLocaleString()}`,
    editor: (value, onChange) => (
      <input type="number" value={value} onChange={(e) => onChange(Number(e.target.value))} />
    ),
  },
];

<EditableTable
  columns={columns}
  data={data}
  rowKey={(r) => String(r.id)}
  onChange={setData}
  deletable
  addable
  newRow={() => ({ id: nextId(), name: "", role: "viewer", salary: 0 })}
/>

When to use

Use EditableTable for row-by-row entry inside quotations, invoice details, or staffing configuration. Use Table for read-only display, or ProTable for a full list page with search, toolbar, and pagination.

Import

ts
import { EditableTable } from "@hulianui/ui"

Props

EditableTableProps<T>:

NameTypeDefaultDescription
columns*EditableColumn<T>[]-Column definitions described below.
data*T[]-Controlled data array.
rowKey*(row: T) => string-Stable row key.
addablebooleanfalseShows the add-row action; requires newRow.
newRow() => T-Factory whose new row immediately enters edit mode.
deletablebooleanfalseEnables row deletion.
validateRow(row: T) => boolean-Blocks save on a falsy result; the consumer renders errors.
classNamestring-Root class name.

Events

EventTypeDescription
onChange(next: T[]) => voidReturns the complete next array after save, delete, or add.

Slots

SlotTypeDescription
summary(data: T[]) => ReactNodeRenders raw tfoot content; the consumer controls <tr> and colSpan.

EditableColumn<T>:

NameTypeDefaultDescription
key*keyof T & string-Data key.
title*ReactNode-Column title.
editablebooleanfalseMakes the cell editable; false stays read-only during editing.
render(value, row) => ReactNode-Display renderer; defaults to the raw value.
editor(value, onChange, row) => ReactNode-Edit renderer; defaults to a text input writing into the draft.
widthnumber-Width in pixels.
align"left" | "center" | "right""left"Cell alignment.

Example

tsx
const [data, setData] = useState(rows);
const columns: EditableColumn<Row>[] = [
  { key: "name", title: "Name", editable: true, width: 160 },
  { key: "salary", title: "Monthly salary", editable: true, align: "right",
    render: (v) => `$${Number(v).toLocaleString()}`,
    editor: (v, onChange) => (
      <input type="number" value={v as number}
        onChange={(e) => onChange(Number(e.target.value))} />
    ) },
];

<EditableTable<Row>
  columns={columns}
  data={data}
  rowKey={(r) => String(r.id)}
  onChange={setData}
  addable
  deletable
  newRow={() => ({ id: Date.now(), name: "", salary: 0 })}
/>

Usage notes

  • Memoize columns (same root cause as Table): TanStack's flexRender renders a function cell as a component type, so a changed identity unmounts and remounts the cell. With an input inside, a controlled field loses focus on every keystroke and an onBlur submit fires on the remount blur, committing a half-typed value. Never put a per-keystroke value in the useMemo dependencies, and prefer uncontrolled inputs for inline editing.
  • Data is controlled. Write next from onChange back to state or saves and row changes will not appear.
  • validateRow only blocks saving; render any validation message inside a custom editor.
  • summary is raw table-footer content, so the consumer owns column spans and alignment.

Related

Table · Book3D · ProTable · PricingTable · JsonViewer · List

PreviousJsonViewerData DisplayNextList

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • Usage notes
    • Related