From b36720937d7276ed344979edb83b0e281a75d9df Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Thu, 29 Jun 2023 21:03:12 -0400 Subject: [PATCH] fix: `onBeforeAppendCell` should only be used when it's a string (#802) - the `onBeforeAppendCell` event can be used to return CSS classes as shown in this [example2-formatters-event.html](http://6pac.github.io/SlickGrid/examples/example2-formatters-event.html), however when the user doesn't define or use this event then its result is always a `true` boolean and the way that the code was implemented, it was always showing "true" as a CSS class which we don't need at all - the original implementation was found in this old [commit](https://github.com/6pac/SlickGrid/commit/bef3203d722b96853a312929a74121eac15ebed5) and on top of that `onBeforeAppendCell` event is actually deprecated to use. --- slick.grid.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/slick.grid.js b/slick.grid.js index 4dd2ecd8..b2787c1d 100644 --- a/slick.grid.js +++ b/slick.grid.js @@ -3459,9 +3459,13 @@ if (typeof Slick === "undefined") { } // get addl css class names from object type formatter return and from string type return of onBeforeAppendCell + // we will only use the event result as CSS classes when it is a string type (undefined event always return a true boolean which is not a valid css class) const evt = trigger(self.onBeforeAppendCell, { row: row, cell: cell, value: value, dataContext: item }); - var addlCssClasses = evt.getReturnValue() || ''; - addlCssClasses += (formatterResult && formatterResult.addClasses ? (addlCssClasses ? ' ' : '') + formatterResult.addClasses : ''); + var appendCellResult = evt.getReturnValue(); + var addlCssClasses = typeof appendCellResult === 'string' ? appendCellResult : ''; + if (formatterResult && formatterResult.addClasses) { + addlCssClasses += (addlCssClasses ? ' ' : '') + formatterResult.addClasses; + } var toolTip = formatterResult && formatterResult.toolTip ? "title='" + formatterResult.toolTip + "'" : ''; var customAttrStr = '';