@3mo/data-grid

中文文档
0.41.0发布于 2026/10/30MITTypeScriptES Module构建来源已验证近 30 天下载 3749

A web component for data grids with typed columns, sorting, selection, pagination, row details and inline editing.

原始使用文档
文档目录32 节
  1. Installation
  2. Usage
  3. Examples
  4. Accessibility
  5. API
  6. mo-data-grid
  7. mo-data-grid-cell
  8. mo-data-grid-column-header
  9. mo-data-grid-footer
  10. mo-data-grid-header
  11. mo-data-grid-header-separator
  12. mo-data-grid-primary-context-menu-item
  13. mo-data-grid-column-boolean
  14. mo-data-grid-column
  15. mo-data-grid-column-deletion
  16. mo-data-grid-column-icon-button
  17. mo-data-grid-column-image
  18. mo-data-grid-column-text
  19. mo-data-grid-column-date
  20. mo-data-grid-column-date-range
  21. mo-data-grid-column-date-time
  22. mo-data-grid-column-date-time-range
  23. mo-data-grid-column-image-preview
  24. mo-data-grid-image-preview
  25. mo-data-grid-image-preview-button
  26. mo-data-grid-column-currency
  27. mo-data-grid-column-number
  28. mo-data-grid-column-percent
  29. mo-data-grid-footer-sum
  30. mo-data-grid-default-row
  31. Links
  32. License

Data Grid

A web component for data grids with typed columns, sorting, selection, pagination, row details and inline editing.

npm Documentation

A table that shows an array of objects as rows, with selection, sorting, pagination, details, editing and CSV export.

The grid is as tall as its rows, and scrolls them within a height, a max-height or a share of a container of a definite size.

Installation

npm install @3mo/data-grid
import '@3mo/data-grid'

Usage

<mo-data-grid .data=${twentyPeople} editability='never'>
    <mo-data-grid-column-image heading='Avatar' dataSelector='avatar' tooltipSelector='name'></mo-data-grid-column-image>
    <mo-data-grid-column-text heading='Name' dataSelector='name'></mo-data-grid-column-text>
    <mo-data-grid-column-number heading='Age' dataSelector='age'></mo-data-grid-column-number>
    <mo-data-grid-column-text heading='Address' dataSelector='address'></mo-data-grid-column-text>
    <mo-data-grid-column-date heading='Birth Date' dataSelector='birthDate'></mo-data-grid-column-date>
</mo-data-grid>

Examples

  • Bound Columns — DataGridColumnBinder.for(Person).bind(keyPath) takes a column's data selector from the key path, its heading from @label and its description from @description.
  • Sticky Columns — sticky pins a column to the start, to the end or to both while the others scroll by; the selection and menu columns stick as well.
  • Custom Cell Style — contentStyle styles a cell by its value: negative balances in red, positive ones in green.
  • Column Menu Items — A column element of your own adds items to the menu under its heading - click the heading of the colored Address column.
  • Sums — sumHeading totals a number column in the footer, over the selected rows while there are any; the sum slot takes totals of your own.
  • Selection — isDataSelectable decides which rows can be selected, here only adults.
  • Details — getRowDetailsTemplate renders what a row opens into, and hasDataDetail decides which rows have details, here only adults.
  • Sub Data Grid — The details can hold any template, such as a grid of the row's children.
  • Sub Rows — subDataGridDataSelector names the key path of a row's children, which open as sub rows under the same columns, level by level.
  • Editing — Here every editable cell edits at once, and nonEditable takes a predicate that keeps the ages over 30 read-only.
  • Sorting — sorting sets the order to start with, by name and then by age; the arrow of a heading sorts by its column, and Shift+click adds it to the order.
  • Reordering — reorderability adds a grip to drag rows by, and each drop fires reorder, which the Actions panel logs.
  • Filters — Elements in the filter slot open with the toolbar's filter button; they continue its row while they fit and wrap into rows of their own otherwise.
  • Primary Action — The primary-action slot places an element at the very end of the toolbar, after its icon buttons.
  • Primary Action With Split Button — Composite actions fit the slot as well, such as a split button with more options.
  • Context Menu — getRowContextMenuTemplate gives each row a menu, opened by a right click or its ⋮ button; primaryContextMenuItemOnDoubleClick runs the bold item on a double click.
  • Virtualization — A thousand rows on one page: scroll through them, select them all or export them.
  • Virtualized Sub Rows — 25 rows open into 40 sub rows each, like a products page with every variant expanded through detailsOpen; scroll through it and watch the scrollbar hold still.
  • Constrained Height — A height, a max-height or a share of a flex or grid container of a definite size gives the grid a height, which it takes and scrolls its rows in.
  • Export — exportable adds a button to the footer that downloads the rows as CSV, sub rows included.
  • Empty State — Without data, the grid shows an empty state, which the error-no-content slot replaces.
  • In A Card — In a mo-card, the grid spans the card's full width under its heading.
  • Custom Data Grid — Arrow keys move between cells, Space selects, Enter or a double click edits and Ctrl+C copies; a heading sorts when clicked, moves when dragged and resizes by its edge.

Accessibility

A grid, or a treegrid with sub rows, with aria-multiselectable while multiple. The header is a row of columnheaders, where the column sorted first says aria-sort='ascending' or 'descending' and every other sortable one 'none'. Rows are rows with aria-level, aria-setsize and aria-posinset, aria-selected while rows can be selected and aria-expanded where they have details or sub rows; cells are gridcells. One cell is in the tab order and takes real focus. The column headers are not part of the arrow navigation; their buttons are ordinary tab stops.

KeyDoes
The arrowsThe cell in that direction, wrapping at the edges.
Home EndThe first or last cell of the row.
Ctrl Home / EndThe first cell of the grid, or the last.
PageUp PageDownA page of rows up or down.
EnterEdits an editable cell; otherwise clicks it, which selects the row with selectOnClick and opens its details with detailsOnClick.
Enter EscapeWhile editing: ends it and returns to the cell; Enter commits, except in a text area.
Ctrl or ⌘ CCopies the cell's text.

With selectOnClick, moving to a cell selects its row, and Shift extends the selection. Where it differs from the ARIA practices: the arrows wrap, Space does not select a row, and in a tree grid ArrowRight and ArrowLeft move between cells rather than opening and closing rows.

API

mo-data-grid

Properties

NameAttributeTypeDefaultDescription
rowsDataGridRow<TData, TDetailsElement>[]The rendered rows, sub rows included, in the order of their records.
resolvedPagination{ readonly strategy: DataGridPaginationStrategy; readonly size: DataGridPaginationSize; } | undefinedResolves effective pagination configuration from property, static default, and fallback.
datadataTData[]"new Array<TData>()"The data to be displayed in the DataGrid. It is an array of objects, where each object represents a row.
columnscolumnsDataGridColumn<TData, any>[]The columns of the DataGrid, composed of their definitions and modifications. Assigning it gives the definitions in code, which column elements override.
headerHiddenheaderHiddenbooleanfalseWhether the header should be hidden.
pagepagenumber1The current page.
paginationpaginationDataGridPagination | undefinedHow the rows are paged: a strategy, pages or scroll, and a size, a number or auto, e.g. pages, pages 50 or 50. auto pages as many rows as fit the grid's height, or
sortingsortingDataGridSorting<TData> | undefinedThe sorting mode. It is an object with selector and strategy properties.
selectabilityselectabilitySelectability | undefinedThe selection mode. Defaults to 'single' if context menus available, 'undefined' otherwise.
isDataSelectableisDataSelectable((data: TData) => boolean) | undefinedWhether data of a given row is selectable.
selectedDataselectedDataTData[]"new Array<TData>()"The selected data.
selectOnClickselectOnClickbooleanfalseWhether the row should be selected on click.
selectionBehaviorOnDataChangeselectionBehaviorOnDataChangeSelectabilityBehaviorOnItemsChange"reset"The behavior of the selection when the data changes.
reorderabilityreorderabilityboolean | undefinedWhether rows can be dragged into another order, which works while nothing is sorted and no row has details or sub rows.
multipleDetailsmultipleDetailsbooleanfalseWhether multiple details can be opened at the same time.
detailsOpendetailsOpenbooleanfalseOpens the details of rows as they arrive, until it is turned off. The user may still close them. Requires "multipleDetails".
subDataGridDataSelectorsubDataGridDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe key path of the sub data grid data.
hasDataDetailhasDataDetail((data: TData) => boolean) | undefinedWhether the data has a detail.
detailsOnClickdetailsOnClickbooleanfalseWhether the details should be opened on click.
primaryContextMenuItemOnDoubleClickprimaryContextMenuItemOnDoubleClickbooleanfalseWhether a double or middle click on a row clicks the mo-data-grid-primary-context-menu-item of its context menu.
editabilityeditabilityDataGridEditability"never"The editability mode.
getRowDetailsTemplategetRowDetailsTemplate((data: TData) => HTMLTemplateResult) | undefinedA function which returns a template for the details of a given row.
getRowContextMenuTemplategetRowContextMenuTemplate((data: TData[]) => HTMLTemplateResult) | undefinedA function which returns a template for the context menu of a given row.
filtersOpenfiltersOpenbooleanfalseWhether the elements of the filter slot are shown. The filter button of the toolbar toggles it.
hasAlternatingBackgroundhasAlternatingBackgroundbooleanWhether the rows should have alternating background.
cellFontSizecellFontSizenumber"value"The font size of the cells in rem, between 0.8 and 1.2. Defaults to DataGrid.cellRelativeFontSize, 0.8.
rowHeightrowHeightnumber"DataGrid.rowHeight.value"The height of the rows in pixels, between 30 and 60. Defaults to DataGrid.rowHeight, 35.
exportableexportablebooleanfalseWhether the DataGrid is exportable. This will show an export button in the footer.

Events

NameDetail
dataChangeTData[]
selectionChangeTData[]
pageChangenumber
paginationChangeDataGridPagination | undefined
columnsChangeDataGridColumn<TData, any>[]
sortingChangeDataGridRankedSortDefinition<TData>[]
reorderDataGridReorderChange<TData>[]
rowDetailsOpenDataGridRow<TData, TDetailsElement>
rowDetailsCloseDataGridRow<TData, TDetailsElement>
rowClickDataGridRow<TData, TDetailsElement>
rowDoubleClickDataGridRow<TData, TDetailsElement>
rowMiddleClickDataGridRow<TData, TDetailsElement>
cellEditDataGridCell<any, TData, TDetailsElement>

Slots

NameDescription
columnThe column elements, which assign themselves to it when placed in the grid. It is hidden.
toolbarThe horizontal bar above DataGrid's contents.
toolbar-actionA slot for action icon-buttons in the toolbar which are displayed on the end.
filterElements which filter DataGrid's data. When expanded, they continue the toolbar's row if they all fit into its remaining space, otherwise they wrap into rows of their own. It is toggled through an icon-button in the toolbar.
sumA horizontal bar in the DataGrid's footer for showing sums. Calculated sums are also placed here by default.
primary-actionA slot at the very end of the toolbar expecting primary action elements (e.g. an "add" button) to be placed in. Slotted elements replace the slot's default content, but complement primary actions generated outside of it e.g. EntityDataGrid's create button, which is suppressed via "primaryActionHidden" instead.
error-no-contentA slot for displaying an error message when no data is available.

CSS custom properties

NameDescription
--mo-data-grid-footer-backgroundThe background of the footer.
--mo-data-grid-cell-paddingThe inline padding of the cells. Defaults to 0.5rem.
--mo-data-grid-column-sub-row-indentationThe indentation of the first column in the sub row. Defaults to 20px.

mo-data-grid-cell

Properties

NameAttributeTypeDefault
valuevalueTValue
columncolumnDataGridColumn<TData, TValue>
rowrowDataGridRow<TData, TDetailsElement>

mo-data-grid-column-header

Properties

NameAttributeTypeDefaultDescription
columncolumnDataGridColumn<unknown, any>
menuOpenmenuOpenbooleanfalse
templateHTMLTemplateResultThe template rendered into renderRoot. Invoked on each update to perform rendering tasks.

Properties

NameAttributeTypeDefault
dataGriddataGridDataGrid<TData, any>
pagepagenumber1

mo-data-grid-header

Properties

NameAttributeTypeDefault
dataGriddataGridDataGrid<TData, any>
overlayOpenoverlayOpenbooleanfalse

mo-data-grid-header-separator

The handle resizing a column, drawing a line where the pointer is while it drags.

Properties

NameAttributeTypeDefault
columncolumnDataGridColumn<unknown, any>

mo-data-grid-primary-context-menu-item

Properties

NameAttributeTypeDefaultDescription
openopenbooleanfalseWhether the submenu is open.
disableddisabledbooleanfalseWhether the list item is disabled
iconiconMaterialIcon | undefinedIcon to be displayed in the list item
preventClickOnSpacepreventClickOnSpacebooleanfalseWhether the list item should prevent click on space

Slots

NameDescription
submenuThe items of the submenu.
(default)Default slot for content

CSS parts

NameDescription
iconThe icon before the content.

mo-data-grid-column-boolean

A column showing a boolean as a dot, colored for true and for false, and nothing for undefined.

Properties

NameAttributeTypeDefaultDescription
trueColortrueColorstring"var(--mo-color-green)"The color of the dot for true values
falseColorfalseColorstring"var(--mo-color-red)"The color of the dot for false values
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"center"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column

Properties

NameAttributeTypeDefaultDescription
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-deletion

Properties

NameAttributeTypeDefaultDescription
preventpreventbooleanfalsePrevents the deletion button from being displayed
iconiconMaterialIcon"delete"The icon to display. Defaults to 'delete'
tooltiptooltipstring | undefinedThe tooltip of the buttons
disableddisabled((data: TData) => boolean) | undefinedWhether the button of a row is disabled
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleantrueWhether the column is sortable
nonEditablenonEditablebooleantrueWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getEditContentTemplategetEditContentTemplate(_: unknown, data?: TData | undefined) => HTMLTemplateResult"getContentTemplate"The edit content template of the column.
getContentTemplateThe content template of the column.

Events

NameDetailDescription
deleteTData
iconClickTDataDispatched with the row's data when its button is clicked

mo-data-grid-column-icon-button

A column with an icon button per row, which stays clickable while the row is edited.

Properties

NameAttributeTypeDefaultDescription
iconiconMaterialIconThe icon of the buttons
tooltiptooltipstring | undefinedThe tooltip of the buttons
disableddisabled((data: TData) => boolean) | undefinedWhether the button of a row is disabled
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleantrueWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getEditContentTemplategetEditContentTemplate(_: unknown, data?: TData | undefined) => HTMLTemplateResult"getContentTemplate"The edit content template of the column.
getContentTemplateThe content template of the column.

Events

NameDetailDescription
iconClickTDataDispatched with the row's data when its button is clicked

mo-data-grid-column-image

Properties

NameAttributeTypeDefaultDescription
tooltipSelectortooltipSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | ((data: TData) => string | undefined) | undefinedThe data selector of the column to use as a tooltip. If a function is provided, it will be called with the data as an argument.
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleantrueWhether the column is sortable
nonEditablenonEditablebooleantrueWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-text

Properties

NameAttributeTypeDefaultDescription
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-date

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsDateTimeFormatOptions | undefinedOptions to pass to DateTime.prototype.format()
precisionprecisionFieldDateTimePrecision"Day"The precision of the date/time.
pickerHiddenpickerHiddenbooleanfalseHides the date/time picker
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-date-range

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsDateTimeFormatOptions | undefinedOptions to pass to DateTime.prototype.format()
precisionprecisionFieldDateTimePrecision"Day"The precision of the date/time.
pickerHiddenpickerHiddenbooleanfalseHides the date/time picker
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-date-time

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsDateTimeFormatOptions | undefinedOptions to pass to DateTime.prototype.format()
precisionprecisionFieldDateTimePrecision"Minute"The precision of the date/time.
pickerHiddenpickerHiddenbooleanfalseHides the date/time picker
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-date-time-range

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsDateTimeFormatOptions | undefinedOptions to pass to DateTime.prototype.format()
precisionprecisionFieldDateTimePrecision"Minute"The precision of the date/time.
pickerHiddenpickerHiddenbooleanfalseHides the date/time picker
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-image-preview

A column with a button per row which previews the row's image in a popover. Its value is the image source unless getSource resolves it, e.g. from a file ID.

Properties

NameAttributeTypeDefaultDescription
getSource(value: TValue) => DataGridImagePreviewSourceResolves a value to its image source, possibly asynchronously, when its preview opens.
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"start"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleantrueWhether the column is sortable
nonEditablenonEditablebooleantrueWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-image-preview

Properties

NameAttributeTypeDefaultDescription
valuevalueunknownThe value whose image is previewed, resolved to an image source by getSource.
getSourcegetSource((value: unknown) => DataGridImagePreviewSource) | undefinedResolves the value to an image source, which is the value itself by default.
imageHiddenimageHiddenbooleanfalseWhether to show only the slotted content without the image.

Slots

NameDescription
(default)Content shown above the image.
closeAn action to close the preview, shown next to the content.

mo-data-grid-image-preview-button

Properties

NameAttributeTypeDefaultDescription
valuevalueunknownThe value whose image is previewed.
getSourcegetSource((value: unknown) => DataGridImagePreviewSource) | undefinedResolves the value to an image source.

Slots

NameDescription
(default)Content shown above the image in the preview.

mo-data-grid-column-currency

Properties

NameAttributeTypeDefaultDescription
currencycurrencyCurrency | undefinedThe currency of the values.
currencyDataSelectorcurrencyDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe key path to the currency of the values.
formatOptionsformatOptionsNumberFormatOptions | undefined
sumHeadingsumHeadingstring | undefined"undefined"
minminnumber | undefined
minDataSelectorminDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
maxmaxnumber | undefined
maxDataSelectormaxDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
stepstepnumber | undefined
stepDataSelectorstepDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"end"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-number

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsNumberFormatOptions | undefined
sumHeadingsumHeadingstring | undefined"undefined"
minminnumber | undefined
minDataSelectorminDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
maxmaxnumber | undefined
maxDataSelectormaxDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
stepstepnumber | undefined
stepDataSelectorstepDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"end"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

mo-data-grid-column-percent

Properties

NameAttributeTypeDefaultDescription
formatOptionsformatOptionsNumberFormatOptions | undefined
sumHeadingsumHeadingstring | undefined"undefined"
minminnumber | undefined
minDataSelectorminDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
maxmaxnumber | undefined
maxDataSelectormaxDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
stepstepnumber | undefined
stepDataSelectorstepDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefined
dataGriddataGridDataGrid<TData, any> | undefined
widthwidthstring"max-content"The width of the column
hiddenhiddenbooleanfalseWhether the column is hidden. The column can be made visible by the user in the settings panel if available.
headingheadingstring""The heading of the column
textAligntextAlignDataGridColumnAlignment"end"The text alignment of the column
descriptiondescriptionstring | undefinedThe description of the column. It will be displayed as a tooltip on the heading.
dataSelectordataSelectorobject extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : neverThe data selector of the column
sortDataSelectorsortDataSelector(object extends Required<TData> ? string : TData extends readonly any[] ? Extract<keyof TData, `${number}`> | Extract<keyof TData, string> | SubKeyPathOf<...> : TData extends object ? Extract<...> | SubKeyPathOf<...> : never) | undefinedThe data selector of the column
nonSortablenonSortablebooleanfalseWhether the column is sortable
nonEditablenonEditableboolean | Predicate<TData>falseWhether the column is editable
stickystickyDataGridColumnSticky | undefinedThe sticky position of the column, either 'start', 'end', or 'both'
contentStylecontentStyleDataGridColumnContentStyle<TData, TValue> | undefinedThe content style of the column. It can be a string, CSSResult, or a function that returns either based on the cell value and data.
getContentTemplateThe content template of the column.
getEditContentTemplateThe edit content template of the column.

Properties

NameAttributeTypeDefault
headingheadingstring""

Slots

NameDescription
(default)Sum of values

mo-data-grid-default-row

Properties

NameAttributeTypeDefault
dataRecorddataRecordDataRecord<TData>

Events

NameDetail
contextmenu

License

MIT © 3MO GmbH

版本与发布记录

@3mo/data-grid 共发布 362 个版本,首次发布于 2023/05/12;过去 12 个月发布了 76 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.41.0latest2026/10/307 天前
0.40.02026/10/2610 天前
0.39.02026/10/2017 天前
0.38.92026/10/1027 天前
0.38.82026/10/0829 天前
0.38.72026/10/0729 天前

其他发布通道:alpha → 0.12.6-preview.2,preview → 0.38.0-preview.0。

关于 @3mo/data-grid 的常见问题

@3mo/data-grid 是什么?

A web component for data grids with typed columns, sorting, selection, pagination, row details and inline editing.

如何安装 @3mo/data-grid?

在项目目录运行 npm install @3mo/data-grid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@3mo/tab(x)、@3mo/flex(x)、@3mo/grid(x)、@3mo/icon(x)、@3mo/line(x)、@3mo/menu(>=0.11.0)、@a11d/lit(>=0.14.1)、@3mo/theme(>=0.4.x)、@3mo/anchor(x)、@3mo/heading(x)、@3mo/popover(>=0.11.0)、@3mo/section(x)、@3mo/tooltip(>=0.11.0)、@3mo/checkbox(x)、@3mo/scroller(>=0.5.0)、@3mo/splitter(x)、@3mo/hierarchy(x)、@3mo/downloader(x)、@3mo/empty-state(x)、@3mo/icon-button(x)、@3mo/text-fields(x)、@3mo/context-menu(>=0.7.0)、@3mo/localization(x)、@3mo/navigability(x)、@3mo/select-field(x)、@3mo/expandability(x)、@3mo/number-fields(x)、@3mo/selectability(>=0.3.0)、@3mo/reorderability(x)、@3mo/resize-observer(x)、@3mo/slot-controller(x)、@3mo/date-time-fields(x)、@a11d/lit-application(x)、@3mo/circular-progress(x)、@3mo/pointer-controller(>=1.6.0)、@3mo/instanceof-attribute-controller(x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@3mo/data-grid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@3mo/data-grid 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@3mo/data-grid 可以商用吗?

@3mo/data-grid 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@3mo/data-grid 的下载量有多少?

根据 npm 官方下载统计,@3mo/data-grid 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,749 次,日均约 125 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@3mo/data-grid 还在维护吗?

最新版本 0.41.0 发布于 2026/10/30(7 天前);至今共发布 362 个版本,其中过去 12 个月发布了 76 个;首次发布于 2023/05/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。