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

これで問題が解決するかどうかはわかりませんが、カスタム スタイル関数の最後の行が次のようになっているとよいでしょう。

(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 に答える