fix: Date Column editing issue.
docs: add some examples.
This commit is contained in:
@ -131,6 +131,10 @@ export class GridColumn {
|
||||
* @virtual
|
||||
*/
|
||||
|
||||
/**
|
||||
* 复写 [toString]{@linkcode String#toString} 方法
|
||||
* @private
|
||||
*/
|
||||
static toString() { return '[object Column]' }
|
||||
}
|
||||
|
||||
@ -417,6 +421,8 @@ export class GridIconColumn extends GridColumn {
|
||||
}
|
||||
|
||||
export class GridDateColumn extends GridColumn {
|
||||
static get editing() { return true };
|
||||
|
||||
static createEdit(trigger, col, _container, vals) {
|
||||
let enabled = col.enabled;
|
||||
if (typeof enabled === 'string') {
|
||||
@ -428,7 +434,15 @@ export class GridDateColumn extends GridColumn {
|
||||
return super.create();
|
||||
}
|
||||
const date = createDateInput(col.dateMin, col.dateMax);
|
||||
// date.addEventListener('change', trigger);
|
||||
date.addEventListener('change', () => {
|
||||
if (vals.__editing == null) {
|
||||
vals.__editing = {
|
||||
[col.key]: true
|
||||
}
|
||||
} else {
|
||||
vals.__editing[col.key] = true;
|
||||
}
|
||||
});
|
||||
date.addEventListener('blur', trigger);
|
||||
return date;
|
||||
}
|
||||
|
@ -210,6 +210,8 @@ let r = lang;
|
||||
* @property {(@deprecated)} [bgFilter] - **已过时**<br/>_根据返回值设置单元格背景色_
|
||||
* @property {object} [events] - 给单元格元素附加事件(事件函数上下文为数据行对象)
|
||||
* @property {Function} events.{event} - 事件回调函数
|
||||
* @property {Function} events.{event}.{this} - 上下文为行数据对象
|
||||
* @property {Function} events.{event}.e - 事件参数
|
||||
* @property {(object | GridItemObjectCallback)} [attrs] - 根据返回值设置单元格元素的附加属性,允许直接设置对象也支持调用如下函数返回对象
|
||||
* @property {GridColumnDefinition} attrs.{this} - 上下文为列定义对象
|
||||
* @property {GridItem} attrs.item - 行数据对象
|
||||
@ -244,12 +246,33 @@ let r = lang;
|
||||
* {
|
||||
* key: 'name',
|
||||
* // type: Grid.ColumnTypes.Common,
|
||||
* caption: 'Name'
|
||||
* caption: 'Name',
|
||||
* captionStyle: {
|
||||
* 'font-style': 'italic'
|
||||
* },
|
||||
* width: 150,
|
||||
* allowFilter: true
|
||||
* },
|
||||
* {
|
||||
* key: 'birthday',
|
||||
* type: Grid.ColumnTypes.Date,
|
||||
* caption: 'Birthday',
|
||||
* width: 120,
|
||||
* dateMin: '1900-01-01',
|
||||
* dateMax: '2025-01-01',
|
||||
* dateValueFormatter: toDateValue
|
||||
* },
|
||||
* {
|
||||
* key: 'age',
|
||||
* type: Grid.ColumnTypes.Input,
|
||||
* caption: 'Age'
|
||||
* caption: 'Age',
|
||||
* enabled: false,
|
||||
* align: 'right',
|
||||
* filter: item => {
|
||||
* const ms = new Date() - new Date(item.birthday);
|
||||
* const age = Math.floor(ms / 1000 / 60 / 60 / 24 / 365);
|
||||
* return String(age);
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* key: 'sex',
|
||||
@ -267,14 +290,31 @@ let r = lang;
|
||||
* caption: 'Active'
|
||||
* },
|
||||
* {
|
||||
* key: 'birthday',
|
||||
* type: Grid.ColumnTypes.Date,
|
||||
* caption: 'Birthday'
|
||||
* },
|
||||
* {
|
||||
* key: 'remove',
|
||||
* type: Grid.ColumnTypes.Icon,
|
||||
* text: 'times'
|
||||
* text: 'times',
|
||||
* resizable: false,
|
||||
* sortable: false,
|
||||
* orderable: false,
|
||||
* tooltip: 'Remove',
|
||||
* events: {
|
||||
* onclick: () => {
|
||||
* showConfirm('Remove', 'Are you sure you want to remove this person?', [
|
||||
* {
|
||||
* key: 'yes',
|
||||
* text: 'Yes',
|
||||
* trigger: () => {
|
||||
* console.log('yes');
|
||||
* return true;
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* key: 'no',
|
||||
* text: 'No'
|
||||
* }
|
||||
* ], 'question')
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* ]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user