dojox DataGrid onStyleRow第一次工作,然后不再工作

时间:2011-08-20 15:01:39

标签: dojo dojox.grid.datagrid

我正在尝试使用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();

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分: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);
});
相关问题