我无法更改 Sencha Extreact 网格中的样式。
例如:
我想将所有列的字体颜色更改为灰色。我使用渲染器道具来更改其他列的字体颜色。
这是网格的示例代码:
<ExtGrid
className="ppa"
store={store}
scrollable={true}
plugins={{
gridfilters: true,
gridsummaryrow: true
}}
rowLines={true}
style={{margin: 20}}
grouped={true}
height="755"
>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="10%" width="100%" filter='string' summaryRenderer={summarizeDate}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={summarizeLoad}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={averageSpeed}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={averageSpeed}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={averageSpeed}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeTime}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeTime}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeTime}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeTime}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeTime}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="8%" width="100%" filter='string' summaryRenderer={summarizeDuration}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={summarizeDistance}/>
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="7%" width="100%" filter='number' summaryRenderer={summarizeDistance}/>
</ExtGrid>
这是摘要渲染器道具的示例代码:
const summarizeDate = (grid, context) => {
return context.records.length + ' Trips'
}
const summarizeDuration = (grid, context) => {
const sum = sumItemsInsideJSONArray(context.records, 'duration')
return convertSecondToHMS(sum)
}
const summarizeTime = (grid, context) => {
const sum = sumItemsInsideJSONArray(context.records, 'time')
return convertSecondToHMS(sum)
}
const summarizeDistance = (grid, context) => {
const sum = sumItemsInsideJSONArray(context.records, 'distance')
return changeValueTo1DecimalPoint(sum) + ' km'
}
const summarizeLoad = (grid, context) => {
const sum = sumItemsInsideJSONArray(context.records, 'load')
return changeValueTo1DecimalPoint(sum) + ' ton'
}
const averageSpeed = (grid, context) => {
const average = averageItemsinJSONArray(context.records, 'speed')
return changeValueTo1DecimalPoint(average) + ' km/h'
}
现在,如果我将渲染器道具添加到其中一列:
<ExtColumn text="<censored>" dataIndex="<censored>" align="center" maxWidth="10%" width="100%" filter='string' summaryRenderer={summarizeDate} renderer={renderGreyFontColor.bind(this, 'number')}/>
使用渲染器道具的功能:
const renderGreyFontColor = (format, value) => (
<span style={{ color: 'slategray'}}>
{value}
</span>
)
我认为这是因为上下文(表数据)格式和值已从非 null 和已定义的数组类型更改为未定义的对象类型。
我尝试了其他方法来更改字体颜色,例如:
- 在 CSS 中使用颜色规则(在 CSS 文件中添加一个类选择器,然后将其插入到 ExtGrid 组件中的 className 属性中)
- 使用 JSX(在 ExtGrid 组件中的 style 属性中添加颜色规则样式)
- 使用 SASS
- 使用 Webpack
但上述代码都不起作用。
那么如果有汇总行,如何将所有列的字体颜色改为灰色呢?