2

I want to style a single row and avoid defining formatters for each cell of my row. Is there an equivalent of the onStyleRow event for the new Dojo dgrid widget?

Thanks.

medokr
  • 441
  • 1
  • 5
  • 16
maxxyme
  • 2,164
  • 5
  • 31
  • 48
  • 1
    Based on what I can understand, it seems the [onStyleRow](https://github.com/SitePen/dgrid/pull/561) was abused. This [post](https://github.com/SitePen/dgrid/issues/236) shows a possible solution if it meets your needs. – medokr Dec 10 '13 at 16:31
  • Yes, this comment: https://github.com/SitePen/dgrid/issues/236#issuecomment-11508012 but unfortunately this doesn't seem to work in Dojo 1.9 – maxxyme Dec 10 '13 at 17:00
  • OK got it, the code can't be added to the definition of my Dgrid, but in a context, like in a controller, where I actually *create* (with new keyword) my grid. – maxxyme Dec 10 '13 at 18:02
  • Nice job! Could you add your solution to your question for others with similar problem? – medokr Dec 10 '13 at 21:36

1 Answers1

1

I ended up with two distinct solutions:

  1. In the controller using the dgrid, based on the workaround given at https://github.com/SitePen/dgrid/issues/236#issuecomment-11508012

        aspect.after(myDgrid, "renderRow", function(row, args) {
            var data = args[0];
            if (data.unread) {
                domClass.add(row, "unread");
            }
            return row;
        });
    
  2. In my own dgrid definition, but without "use strict" - otherwise this won't work and you'll get this error: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them:

    return declare("com.my.myDgrid", [ Grid, ... ], {
        columns : [ {
            ...
        } ],
    
        renderRow : function() {
            var row = this.inherited(arguments);
            var data = arguments[0];
            if (data.unread) {
                domClass.add(row, "unread");
            }
            return row;
        }
    });
    

The styling is done via this simple CSS rule:

    #myDgridId .unread td {
        font-weight: bold;
    }
maxxyme
  • 2,164
  • 5
  • 31
  • 48