Table Feature Editable
Edit on GitHubThis document describes the Table Feature Editable component in the Components Library.
Overview
Table Feature Editable is a feature of the Table Component that lets you edit and add rows to the table.
Check out an example usage of the Table Feature Editable in the @spryker/table
config.
Component configuration:
columns
—an array with the config for every editable column.create
—an object with the config for the added rows.update
—an object with the config for the existing rows.disableRowKey
—disables the row that contains the mentioned columnid
(see the following example).
<spy-table
[config]="{
dataSource: { ... },
columns: [ ... ],
editable: {
columns: [ ... ],
create: { ... },
update: { ... },
disableRowKey: 'col',
},
}"
>
</spy-table>
Take a closer look at all the options available.
-
columns
—only required properties are listed; the entire interface can be found in Table Design document:id
—a cellid
.type
—a celltype
.typeOptions
–to learn more about the column types available, see Column Type:value
—sets the default value to the newly added row’s cell.
-
create
:addButon
—this object holds theAdd button
configuration such astitle
,icon
, andsize
.cancelButon
—an object with theCancel button
configuration liketitle
andicon
.disableForCols
—an array with the cellids
to be disabled.formInputName
—creates aninput[type=hidden]
element with the specific name.initialData
—initials data for cells and objects with errors for rows and cells.
-
update
:url
—a request url.saveButon
—an object with theSave button
configuration such astitle
andicon
(displayed in theupdate
popup).cancelButon
—an object with theCancel button
configuration such astitle
andicon
(displayed in theupdate
popup).disableForCols
—an array with the cellids
to be disabled.
<spy-table
[config]="{
dataSource: { ... },
columns: [ ... ],
editable: {
columns: [
{ id: 'col1', type: 'edit' },
{ id: 'col2', type: 'edit', typeOptions: { value: 'default' } },
],
create: {
addButton: {
title: 'Add price',
icon: 'icon',
},
cancelButton: {
title: 'Cancel',
icon: 'icon',
},
disableForCols: ['col2'],
formInputName: 'form-input-name',
initialData: {
data: [
{ col1: 'value', col2: 'value' },
{ col1: 'value' },
],
errors: {
0: {
rowError: 'message',
columnErrors: {
col3: 'errorMessage errorMessage errorMessage',
},
},
},
},
},
update: {
url: '/table-update-cell',
saveButton: {
title: 'Save',
icon: 'icon',
},
cancelButton: {
title: 'Cancel',
icon: 'icon',
},
disableForCols: ['col2'],
},
disableRowKey: 'col1',
},
}"
>
</spy-table>
Component registration
Register the component:
declare module '@spryker/table' {
interface TableConfig {
editable?: TableEditableConfig;
}
}
@NgModule({
imports: [
TableModule.forRoot(),
TableModule.withFeatures({
editable: () =>
import('@spryker/table.feature.editable').then(
(m) => m.TableEditableFeatureModule,
),
}),
],
})
export class RootModule {}
// Via HTML
@NgModule({
imports: [
TableModule.forRoot(),
TableEditableFeatureModule,
],
})
export class RootModule {}
<spy-table [config]="config">
<spy-table-editable-feature spy-table-feature></spy-table-editable-feature>
</spy-table>
Interfaces
The following is interfaces for the Table Feature Editable:
export interface TableEditableColumn extends TableColumn {
typeOptions?: TableEditableColumnTypeOptions;
}
export interface TableEditableColumnTypeOptions extends TableColumnTypeOptions {
editableError?: string;
}
export interface TableEditableConfig extends TableFeatureConfig {
columns: TableEditableColumn[];
create?: TableEditableConfigCreate;
update?: TableEditableConfigUpdate;
disableRowKey?: string;
}
export interface TableEditableConfigCreate {
formInputName: string;
initialData?: TableEditableConfigCreateData;
addButton?: TableEditableConfigButton;
cancelButton?: TableEditableConfigButton;
disableForCols?: string[];
}
export interface TableEditableConfigUpdate {
url: TableEditableConfigUrl;
saveButton?: TableEditableConfigButton;
cancelButton?: TableEditableConfigButton;
disableForCols?: string[];
}
export interface TableEditableConfigCreateData {
data: TableDataRow[];
errors?: TableEditableConfigDataErrors;
}
export interface TableEditableConfigDataErrorsFields {
rowError?: string;
columnErrors?: { [columnId: string]: string | undefined };
}
export type TableEditableConfigDataErrors = TableEditableConfigDataErrorsFields[];
export interface TableEditableConfigUrlObject {
url: string;
method?: string;
}
export type TableEditableConfigUrl = string | TableEditableConfigUrlObject;
export interface TableEditableConfigButtonIcon {
icon: string;
}
export interface TableEditableConfigButtonText
extends Partial<TableEditableConfigButtonIcon> {
title: string;
size?: ButtonSize;
shape?: ButtonShape;
variant?: ButtonVariant;
type?: ButtonType;
}
export type TableEditableConfigButton =
| TableEditableConfigButtonText
| TableEditableConfigButtonIcon;
export interface TableEditableEventData<T = unknown> {
colId: string;
value?: T;
}
export class TableEditableEvent<T = unknown> extends CustomEvent<TableEditableEventData<T>> {
static readonly eventName = 'spy-table-editable';
constructor(detail: TableEditableEventData<T>) {
super(TableEditableEvent.eventName, {
bubbles: true,
cancelable: true,
composed: true,
detail,
});
}
}
export interface TableDatasourceDependableConfig extends DatasourceConfig {
dependsOn: string;
contextKey?: string;
datasource: DatasourceConfig;
}
Thank you!
For submitting the form