【问题标题】:Dojo dgrid: how style a single row?Dojo dgrid:如何设置单行样式?
【发布时间】:2026-01-04 08:45:01
【问题描述】:

我想为单行设置样式并避免为行的每个单元格定义格式化程序。新的Dojo dgrid 小部件是否有等效的 onStyleRow 事件?

谢谢。

【问题讨论】:

  • 据我所知,onStyleRow 似乎被滥用了。这个post 显示了一个可能的解决方案,如果它满足您的需求。
  • 是的,这条评论:github.com/SitePen/dgrid/issues/236#issuecomment-11508012 但不幸的是,这似乎在 Dojo 1.9 中不起作用
  • 好的,代码不能添加到我的 Dgrid 的定义中,但是在上下文中,比如在控制器中,我实际上 create (使用 new关键字)我的网格。
  • 干得好!您能否为其他有类似问题的人添加您的解决方案?

标签: javascript dojo dgrid


【解决方案1】:

我最终得到了两种截然不同的解决方案:

  1. 在使用 dgrid 的控制器中,基于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. 在我自己的 dgrid 定义中,但没有“使用严格” - 否则这将不起作用,您将收到此错误: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;
        }
    });
    

样式是通过这个简单的 CSS 规则完成的:

    #myDgridId .unread td {
        font-weight: bold;
    }

【讨论】: