Forums › Forums › OroPlatform › OroPlatform – How do I? Questions › add css class to report rows or cells
This topic contains 5 replies, has 4 voices, and was last updated by farzam.sabeti 4 years, 11 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- February 15, 2016 at 5:50 am #36189
Hi,
Is it possible to add css class to report grid rows or cells based on condition check? We need to check a condition and for example set background color for rows.
Any suggestion?
Thanks
- CreatorTopic
- AuthorReplies
- February 15, 2016 at 8:03 am #36190
Hello.
The easiest way to do that is to pass column called “row_class_name” to frontend – in this case this column value will be added to grid row class, so you can apply your own styles to this row. If you need to apply this styles to some specific grid – you can write it right into grid configuration, if no – you need to listen to datagrid event (probably, PreBuild) and alter grid configuration there.
Example:
YAML123456789datagrid:grid:source:type: ormquery:select:- "'test' as row_class_name"properties:row_class_name: ~And result:
XHTML1<tr class="test row-click-action">...</tr>If you need to do something more sophisticated that includes JS code – you should add JS datagrid builder and customize grid from frontend side there (example of datagrid builder module).
February 15, 2016 at 11:23 pm #36191Dear Yevhen,
Thank you so much for your perfect reply. The “row_class_name” solution is exactly what we were looking for and should cover our needs.
Thanks again,
AhmadMay 6, 2019 at 10:01 pm #38780Hi
I was looking to add css class to report grid rows based on condition check in oro version 3.1. I did what you said but, that did not work. I expected to see the class name on the <tr> … </tr> tag but, nothing happened.
Can you please guide me?
Thanks
May 7, 2019 at 6:23 am #38793Hi,
Turned out, there’s bug. We’ll fix it.
Here’s patch that fixes the issue:
diff12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455Index: package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/row.js<+>UTF-8===================================================================--- package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/row.js (date 1557226077000)+++ package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/row.js (date 1557233666000)@@ -76,8 +76,9 @@/*** @inheritDoc*/- constructor: function Row() {- Row.__super__.constructor.apply(this, arguments);+ constructor: function Row(options) {+ _.extend(this, _.pick(options, ['rowClassName', 'themeOptions', 'template', 'columns']));+ Row.__super__.constructor.call(this, options);},/**@@ -87,7 +88,6 @@// itemView function is called as new this.itemView// it is placed here to pass THIS within closurevar _this = this;- _.extend(this, _.pick(options, ['themeOptions', 'template', 'columns']));// let descendants override itemViewif (!this.itemView) {this.itemView = function(options) {@@ -206,7 +206,14 @@},className: function() {- return this.model.get('row_class_name');+ var classes = [];+ if (this.rowClassName) {+ classes.push(this.rowClassName);+ }+ if (this.model.get('row_class_name')) {+ classes.push(this.model.get('row_class_name'));+ }+ return classes.join(' ');},/**Index: package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/body.js<+>UTF-8===================================================================--- package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/body.js (date 1557226077000)+++ package/platform/src/Oro/Bundle/DataGridBundle/Resources/public/js/datagrid/body.js (date 1557233468000)@@ -83,7 +83,7 @@model: model,collection: this.filteredColumns,columns: this.columns,- className: this.rowClassName+ rowClassName: this.rowClassName};this.columns.trigger('configureInitializeOptions', Row, rowOptions);return new Row(rowOptions);May 10, 2019 at 11:29 pm #38815That works correctly. Thank you so much.
- AuthorReplies
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.