1

我的应用程序中有一个网格,它在字段中显示日期。现在,如果这一天在上周,我想以粗体格式显示该字段。但在两行显示我想要的输出。我不明白我的病情出在哪里。有人可以帮我吗?这是我的代码如下:

{
            text: 'Start',  
            dataIndex: 'weekstart',
            flex: 1,
            renderer: function(value, metaData){
                var day = new Date(value) - 0,
                lastDay = Ext.Date.getLastDateOfMonth(value)-0,
                lastWeek = lastDay - 7;
                console.log('day >>> '+day,'lastDay >>> '+ lastDay, 'lastWeek >>> '+lastWeek);
                    return day >= lastWeek ? '<b>' + Ext.Date.format(value, 'M d, Y') + '</b>' : Ext.Date.format(value, 'M d, Y') ;
            }
        }
4

2 回答 2

3

您的dayandlastDay是时间戳,要做到这一点,您应该在lastWeek:中使用时间戳lastWeek = lastDay - 7*24*3600*1000

无论如何,IMO 最好用于getRowClass格式化值。在网格配置中尝试指定viewConfig

viewConfig: {
    getRowClass: function(record, rowIndex, rowParams, store){
        var value = record.get('lastChange'),
            day = value.getDate(),
            lastDay = Ext.Date.getDaysInMonth(value),
            lastWeek = lastDay - 6;
        return day >= lastWeek ? 'last-week' : '';
    }
}

在列定义中指定类附加类:tdCls: 'date-column'然后您可以在css中格式化列:

.last-week .date-column {
    font-weight: bold;
}​

工作样本:http: //jsfiddle.net/36n4m/1/

于 2012-12-23T12:39:18.650 回答
0

嗨,我已经完成了,如下所示:

 {
                text: 'Start',  
                dataIndex: 'weekstart',
                width: 84,
                renderer: function(value, metaData, record, row, col, store, gridView){
                    var day = value.getDate(),
                    lastDay = Ext.Date.getDaysInMonth(value),
                    lastWeek = lastDay - 6;
//                    console.log( 'row >>> '+ row,'   day >>> '+ day,'   lastDay >>> '+ lastDay, '   lastWeek >>> '+ lastWeek );
                        return day >= lastWeek ? '<b>' + Ext.Date.format(value, 'M d, Y') + '</b>' : Ext.Date.format(value, 'M d, Y') ;
                }
            }
于 2012-12-23T08:03:31.580 回答