1

我正在尝试使用 DataGrid 制作图例。我的问题是,我希望 Datagrid 中的文本是彩色的。我使用此处概述的 onStyleRow 函数:(http://dojotoolkit.org/reference-guide/dojox/grid/DataGrid.html),它在部署后第一次工作。DataGrid 中的文本呈红色,但如果我在不同的浏览器上刷新或打开尝试,DataGrid 文本不会呈红色,只是标准的黑色。

我想知道我做错了什么,谢谢,这是我的代码:

if(dijit.byId("plotlegend")){
    dijit.byId("plotlegend").destroy();
}

var threadGrid = new dojox.grid.DataGrid({
    id: 'plotlegend',
    store: oStore,
    structure: layout,
    rowsPerPage: 5,
    rowSelector: false,
    autoWidth: true,
    query: {},
    plotsObject: this.plotsObject,
    onStyleRow: function(row){
        var legend = this;
        var item = legend.getItem(row.index);
        if (item){
                var variableName = legend.store.getValue(item, "plot");
            if (variableName){
                var color = "color:red;";
                row.customStyles += color;
            }
        }

        legend.focus.styleRow(row);
        legend.edit.styleRow(row);
    }
},document.createElement('div'));

dojo.byId("plotlegendbc").appendChild(threadGrid.domNode);
threadGrid.startup();
threadGrid.update();
4

2 回答 2

2

不确定这是否会解决您的问题,但最好是自定义样式函数的最后一行是:dojox.grid.DataGrid.prototype.onStyleRow.apply(this, arguments);

(删除 grid.focus.styleRow 和 grid.focus.edit.styleRow 行)此代码将更加向前兼容,因为它直接运行默认的 onStyleRow 函数。

于 2012-06-04T21:21:55.760 回答
1

我在使用dojo.connect处理此事件并正确应用样式方面取得了更大的成功。我没有使用单独的样式,因为 CSS 类是管理样式的更好方法。它更便于维护,因为这样您的 JavaScript 中就不会嵌入单独的样式。这是对我有用的片段。请记住,这是在 Dojo 1.5 上。

var grid = dijit.byId('myDataGrid');
dojo.connect(grid, 'onStyleRow' , this, function(row) {                    
    var item = grid.getItem(row.index);
    if (item) {
        if(item.status != "viewed"){
            row.customClasses += " unRead";
        }else{
            row.customClasses += " read";
        }

        if(item.status == "not active"){
            row.customClasses += " dismissed";
        }
    }
    grid.focus.styleRow(row);
    grid.edit.styleRow(row);
});
于 2011-10-14T19:17:48.737 回答