2

Is there any way to impose a maxLength text allowed in an ag-grid cell, similar to the one on a normal input element?

  <input maxlength="220"/>

No relative documentation was found. Also, no particular situations & more details are needed, in my opinion. Thank you!

Tharindu Lakshan
  • 3,995
  • 6
  • 24
  • 44
Vlad Danila
  • 1,222
  • 3
  • 18
  • 38

2 Answers2

3

agGrid's documentation really isn't clear on this, but it is possible.

agGrid MaxLength

In your column definitions, just add something like this:

this.columnDefs = [
    {
        field: 'Surname',
        minWidth: 100,
        editable: true,
        cellEditor: 'agLargeTextCellEditor',
        cellEditorParams: { maxLength: 200 }
    }
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159
2

Yes, you can control the full flow of input data, but you have to create your own cellEditor for that.

So - it shouldn't be hard to make a simple input validation.

and to achieve your requirements you have to take care of one function within the component:

// 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;
}

Demo

Paritosh
  • 11,144
  • 5
  • 56
  • 74
un.spike
  • 4,857
  • 2
  • 18
  • 38