jqGrid
jqGrid copied to clipboard
setCell not applying formatter
Looks to me that when using the "setCell" method, the value is going into the grid without applying the set formatter. My questions:
- Am I correct in my observation or is it just something in my environment?
- Is this a bug or a feature? :)
- If this is done on purpose, is there a function call I can make by myself to apply the set formatter before calling setCell?
Thanks, Udi
Hello,
Sorry for delay. SetCell method uses a formatting, but there are conditions when this not apply.
See here: https://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L6752
The conditions where the setCell fail are
- rowId and colname does not exists
- the indexRow can not be get with getGridRowById
- the cell can not be get with indexRow.cells[pos]
- if the new cell content is empty string (this can be omited with the 6-th parameter forceupdate) - see docs
Check if these conditions are correct.
Hi Tony,
Well, you pointed me to the interesting area in the code and then I did some debugging from there. Eventually I could see that the formatter IS being called, but the problem was elsewhere. My field is "datetime" type. When the setCell is called manually (like I use it), the formatter is invoked with the "edit" parameter. In that case there's a condition in the below line which needs "reformatAfterEdit" in order to use the formatter. Otherwise it uses the default formatter. Once I added "reformatAfterEdit : true" to my formatoptions, everything started working well. Not sure if this is a bug or just something to live with.
https://github.com/tonytomov/jqGrid/blob/f104df4bbbe6abeafd22d7a5c8784c5da732079f/js/jquery.fmatter.js#L214
Anyway, thank you for the tip.