我无法更改 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'
}
如果我将摘要渲染器函数更改为返回具有所需背景的视图的函数,如下所示:
const averageSpeed = (grid, context) => {
const average = averageItemsinJSONArray(context.records, 'speed')
return (
<div style={{backgroundColor: 'slategray'}}>
{`${changeValueTo1DecimalPoint(average)} km/h`}
</div>
)
}
我尝试了其他方法来更改字体颜色,例如:
- 在 CSS 中使用颜色规则(在 CSS 文件中添加一个类选择器,然后将其插入到 ExtGrid 组件中的 className 属性中)
- 使用 JSX(在 ExtGrid 组件中的 style 属性中添加颜色规则样式)
- 使用 SASS
- 使用 Webpack
但上述代码都不起作用。
那么如何正确更改网格中摘要行的背景呢?