如何在 ag-grid 单元格上设置最大长度
How to set Max Length on ag-grid cells
有什么方法可以在 ag-grid
单元格中强加 maxLength
文本,类似于普通输入元素上的文本?
<input maxlength="220"/>
未找到相关文档。此外,在我看来,不需要特定情况和更多细节。谢谢!
是的,您可以控制整个输入数据流,但您必须为此创建自己的 cellEditor
。
所以 - 进行简单的输入验证应该不难。
要实现您的要求,您必须处理组件中的一项功能:
// Gets called once when editing is finished (eg if enter is pressed).
// If you return true, then the result of the edit will be ignored.
isCancelAfterEnd?(): boolean;
isCancelAfterEnd() {
return !this.isValid(this.eInput.value);
}
isValid(value) {
return value.length <= this.maxLength;
}
agGrid 的文档对此确实不清楚,但这是可能的。
在您的列定义中,只需添加如下内容:
this.columnDefs = [
{
field: 'Surname',
minWidth: 100,
editable: true,
cellEditor: 'agLargeTextCellEditor',
cellEditorParams: { maxLength: 200 }
}
有什么方法可以在 ag-grid
单元格中强加 maxLength
文本,类似于普通输入元素上的文本?
<input maxlength="220"/>
未找到相关文档。此外,在我看来,不需要特定情况和更多细节。谢谢!
是的,您可以控制整个输入数据流,但您必须为此创建自己的 cellEditor
。
所以 - 进行简单的输入验证应该不难。
要实现您的要求,您必须处理组件中的一项功能:
// Gets called once when editing is finished (eg if enter is pressed).
// If you return true, then the result of the edit will be ignored.
isCancelAfterEnd?(): boolean;
isCancelAfterEnd() {
return !this.isValid(this.eInput.value);
}
isValid(value) {
return value.length <= this.maxLength;
}
agGrid 的文档对此确实不清楚,但这是可能的。
在您的列定义中,只需添加如下内容:
this.columnDefs = [
{
field: 'Surname',
minWidth: 100,
editable: true,
cellEditor: 'agLargeTextCellEditor',
cellEditorParams: { maxLength: 200 }
}