简体   繁体   English

如何在网格(EXTJS)中从跨行到行?

[英]how can i make it from span to row in grid(EXTJS)?

The below code does the colour change of the text in the cell.how can it be applied to apply entire row background colour ???? 下面的代码会改变单元格中文本的颜色,如何将其应用于整个行的背景色????

function dataindex(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '%</span>';
        }else if(val < 0){
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    }

You can customize the appearance of grid rows by overriding the getRowClass method of GridView (see Ext JS API ). 您可以通过重写GridViewgetRowClass方法来自定义网格行的外观(请参阅Ext JS API )。

Quoted example from API documentation - see how getRowClass returns a different css class depending on the condition: API文档中引用的示例-查看getRowClass如何根据条件返回不同的CSS类:

viewConfig: {
    forceFit: true,
    showPreview: true, // custom property
    enableRowBody: true, // required to create a second, full-width row to show expanded Record data
    getRowClass: function(record, rowIndex, rp, ds){ // rp = rowParams
        if(this.showPreview){
            rp.body = '<p>'+record.data.excerpt+'</p>';
            return 'x-grid3-row-expanded';
        }
        return 'x-grid3-row-collapsed';
    }
},

After overriding the method, you just need to set up the css definitions with whatever background colors etc. that you wish. 覆盖该方法之后,您只需要使用所需的任何背景色等来设置css定义。

Like Tommi said, getRowClass is what you want to use. 就像Tommi所说的, getRowClass是您要使用的。 If you really want to set the color explicitly, you can append styles to rowParams.tstyle : 如果您确实想显式设置颜色,则可以将样式附加到rowParams.tstyle

viewConfig: {
    getRowClass: function(record, rowIndex, rowParams, store) {
        rowParams.tstyle += "color: green;";
    }
},

But usually it's better to simply return a class name from getRowClass and define the exact colors in CSS file. 但是通常最好只从getRowClass返回一个类名并在CSS文件中定义确切的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM