AG Grid: Better way for validation row - valueSetter?

偶尔善良 提交于 2019-12-18 07:24:29

问题


Is there a better way to validate a row in ag-grid than with valueSetter?

I can achieve the validation with that but I am not sure, if there is a better way.

https://www.ag-grid.com/javascript-grid-value-setters/#properties-for-setters-and-parsers

I want to validate two fields in the row. DateFrom and DateUntil (they are not allow to be null and DateFrom must be lower than DateUntil).


回答1:


There are two ways of possible validation handling:

First: via ValueSetter function

and

Second: via custom cellEditor component

I suggest that it would be better to split the logic between custom components, but as you said you need to validate two cell-values between themselves.

On this case from UI perspective you could try to combine them inside one cell and it would be easily to work with values via one component only.




回答2:


Have a look at this two snippets, these come from our internal knowledge base (accessible to customers)

When editing a value in column 'A (Required)', you will see that it does not allow you to leave it empty. If you leave it empty and return the edit, it will be cancelled.

//Force Cell to require a value when finished editing

https://plnkr.co/edit/GFgb4v7P8YCW1PxJwGTx?p=preview

In this example, we are using a Custom Cell Editor that will also validate the values against a 6 character length rule. While editing, if the value is modified outside of 6 characters, it will appear in red, and when you stop editing the row, the value would be reset, so it only accepts a complete edit if the value is valid.

//Inline Validation while editing a cell 

https://plnkr.co/edit/dAAU8yLMnR8dm4vNEa9T?p=preview



来源:https://stackoverflow.com/questions/52710350/ag-grid-better-way-for-validation-row-valuesetter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!