如何更改Sencha Extreact Grid 产品的样式(摘要行的背景颜色)
How to change the style (background color of the summary row) of Sencha Extreact Grid product
我无法更改 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>
这里是摘要渲染器 prop 的示例代码:
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'
}
如果我将摘要渲染器函数更改为 return 具有所需背景的视图的函数,如下所示:
const averageSpeed = (grid, context) => {
const average = averageItemsinJSONArray(context.records, 'speed')
return (
<div style={{backgroundColor: 'slategray'}}>
{`${changeValueTo1DecimalPoint(average)} km/h`}
</div>
)
}
速度列的摘要行未定义,背景未更改。
我尝试过其他改变字体颜色的方法,例如:
- 使用 CSS 中的颜色规则(在 CSS 文件中添加一个 class 选择器,然后将其插入到 ExtGrid 组件中的 className 属性中)
- 使用JSX(在ExtGrid组件的style属性中添加颜色规则样式)
- 使用SASS
- 使用 Webpack
但上述代码中的 none 有效。
那么如何正确更改网格中摘要行的背景呢?
我自己找到了解决方案。
我在浏览器中使用 检查元素,然后编辑 CSS class 名称的 属性。
我从检查的元素中复制了选择器 #ext-gridsummaryrow-1
,然后更改了元素文本和背景的 属性。
#ext-gridsummaryrow-1 {
background-color: #f6f6f6;
color: black;
}
我无法更改 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>
这里是摘要渲染器 prop 的示例代码:
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'
}
如果我将摘要渲染器函数更改为 return 具有所需背景的视图的函数,如下所示:
const averageSpeed = (grid, context) => {
const average = averageItemsinJSONArray(context.records, 'speed')
return (
<div style={{backgroundColor: 'slategray'}}>
{`${changeValueTo1DecimalPoint(average)} km/h`}
</div>
)
}
速度列的摘要行未定义,背景未更改。
我尝试过其他改变字体颜色的方法,例如:
- 使用 CSS 中的颜色规则(在 CSS 文件中添加一个 class 选择器,然后将其插入到 ExtGrid 组件中的 className 属性中)
- 使用JSX(在ExtGrid组件的style属性中添加颜色规则样式)
- 使用SASS
- 使用 Webpack
但上述代码中的 none 有效。
那么如何正确更改网格中摘要行的背景呢?
我自己找到了解决方案。
我在浏览器中使用 检查元素,然后编辑 CSS class 名称的 属性。
我从检查的元素中复制了选择器 #ext-gridsummaryrow-1
,然后更改了元素文本和背景的 属性。
#ext-gridsummaryrow-1 {
background-color: #f6f6f6;
color: black;
}