英文:
How to replace ag grid checkbox check mark font icon by another one?
问题
我有一个Angular项目,使用bootstrap 4.4.1、ag-grid 27.3和一个全局style.scss文件。我能够在我的TypeScript和HTML文件中使用css类来使用bs图标。
现在,我尝试将ag-grid中的复选框字体图标从"\f106"
更改为"\f272"
来自bootstrap。我在浏览器中看到与字体图标相关的两个主要CSS类是:
具体影响图标的属性是font-size
和content
(默认情况下为粉色)。
所以,我尝试设置图标的css代码,但没有成功,浏览器没有报错,但也没有显示。
是否有可能更改该字体图标?我需要在style.scss中导入一些内容吗?
编辑 1:
尝试了文档中的所有方法(sass、svg和javascript),都无法使其正常工作。
Sass:
在index.html中添加:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">
已经在我的style.scss中引入了以下内容:
@import "../node_modules/ag-grid-community/src/styles/ag-grid.scss";
@import "../node_modules/ag-grid-community/src/styles/ag-theme-material/sass/ag-theme-material-mixin.scss";
以更改复选框已选图标,添加以下代码:
.ag-theme-material .ag-icon-checkbox-checked {
// 尝试了所有3种字体的组合
//--ag-icon-font-family: 'Material Design Icons';
//--ag-icon-font-family: agGridMaterial;
//--ag-icon-font-family: "agGridMaterial";
--ag-icon-font-code-checkbox-checked: '\f00c';
}
Svg:
.ag-theme-material .ag-icon-checkbox-checked {
background: transparent url("https://www.ag-grid.com/example-assets/svg-icons/menu.svg") center/contain no-repeat;
color: transparent;
}
Javascript(GridOptions或Column Def):
@Input() gridOptions: GridOptions = {
// ...
icons: {
checkboxChecked: '<i class="bi bi-check2"></i>', // bootstrap字体图标
},
// ...
}
英文:
I have an Angular project with bootstrap 4.4.1, ag-grid 27.3 and a global style.scss file. I'm able to use bs icons by using the css classes in my typescript and html files.
Now i'm trying to change the checkbox font icon in ag-grid, from "\f106"
to "\f272"
of bootstrap. I see in the browser that the main two css classes involved with the font icon are:
The font-size
and content
properties specifically affect the icon (in pink by default)
So, I tried setting the icon css code, but no luck, the browser is not throwing an error but it's not showing it either.
Is it even possible to change that font icon? Do I need to import something to the style.scss?
Edit 1:
Tried all the approaches (sass, svg and javascript) from the docs and wasn't able to make work neither.
Sass:
Added
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"/>
to index.html. Already had these imports in my style.scss:
@import "../node_modules/ag-grid-community/src/styles/ag-grid.scss";
@import "../node_modules/ag-grid-community/src/styles/ag-theme-material/sass/ag-theme-material-mixin.scss";
And this for changing the checkbox-checked icon
.ag-theme-material .ag-icon-checkbox-checked {
//tried all 3 combinations of font
//--ag-icon-font-family: 'Material Design Icons';
//--ag-icon-font-family: agGridMaterial;
//--ag-icon-font-family: "agGridMaterial";
--ag-icon-font-code-checkbox-checked: '\f00c';
}
Svg:
.ag-theme-material .ag-icon-checkbox-checked{
background: transparent url("https://www.ag-grid.com/example-assets/svg-icons/menu.svg") center/contain no-repeat;
color: transparent;
}
Javascript (GridOptions or Column Def):
@Input() gridOptions: GridOptions = {
...
icons: {
checkboxChecked: '<i class="bi bi-check2"/>',//boostrap font icon
},
...
}
答案1
得分: 2
请阅读Ag-grid自定义图标
您可以通过在index.html
中插入<link>
并在custom.scss
中导入自定义图标字体来使用自定义图标字体。
示例
index.html
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"/>
custom.scss
.ag-theme-alpine {
--ag-icon-font-family: 'Font Awesome 5 Free';
--ag-icon-font-code-aggregation: '\f247';
--ag-icon-font-code-arrows: '\f0b2';
--ag-icon-font-code-asc: '\f062';
--ag-icon-font-code-cancel: '\f057';
--ag-icon-font-code-chart: '\f080';
--ag-icon-font-code-color-picker: '\f576';
--ag-icon-font-code-columns: '\f0db';
--ag-icon-font-code-contracted: '\f146';
--ag-icon-font-code-copy: '\f0c5';
--ag-icon-font-code-cross: '\f00d';
--ag-icon-font-code-desc: '\f063';
--ag-icon-font-code-expanded: '\f0fe';
--ag-icon-font-code-eye-slash: '\f070';
--ag-icon-font-code-eye: '\f06e';
--ag-icon-font-code-filter: '\f0b0';
--ag-icon-font-code-first: '\f100';
--ag-icon-font-code-grip: '\f58e';
--ag-icon-font-code-group: '\f5fd';
--ag-icon-font-code-last: '\f101';
--ag-icon-font-code-left: '\f060';
--ag-icon-font-code-linked: '\f0c1';
--ag-icon-font-code-loading: '\f110';
--ag-icon-font-code-maximize: '\f2d0';
--ag-icon-font-code-menu: '\f0c9';
--ag-icon-font-code-minimize: '\f2d1';
--ag-icon-font-code-next: '\f105';
--ag-icon-font-code-none: '\f338';
--ag-icon-font-code-not-allowed: '\f05e';
--ag-icon-font-code-paste: '\f0ea';
--ag-icon-font-code-pin: '\f276';
--ag-icon-font-code-pivot: '\f074';
--ag-icon-font-code-previous: '\f104';
--ag-icon-font-code-right: '\f061';
--ag-icon-font-code-save: '\f0c7';
--ag-icon-font-code-small-down: '\f107';
--ag-icon-font-code-small-left: '\f104';
--ag-icon-font-code-small-right: '\f105';
--ag-icon-font-code-small-up: '\f106';
--ag-icon-font-code-tick: '\f00c';
--ag-icon-font-code-tree-closed: '\f105';
--ag-icon-font-code-tree-indeterminate: '\f068';
--ag-icon-font-code-tree-open: '\f107';
--ag-icon-font-code-unlinked: '\f127';
--ag-icon-font-code-checkbox-checked: '\f00c';
--ag-icon-font-code-checkbox-unchecked: '\f00d';
}
.ag-theme-alpine .ag-icon,
.ag-theme-alpine .ag-checkbox-input-wrapper,
.ag-theme-alpine .ag-radio-button-input-wrapper {
/* Font Awesome要求所有图标元素都加粗 */
font-weight: bold;
}
/* 选择性地使用Material Design图标替换组和聚合图标 */
.ag-theme-alpine .ag-icon-group {
--ag-icon-font-family: 'Material Design Icons';
--ag-icon-font-code-group: '\F0328';
font-weight: normal;
color: red;
}
.ag-theme-alpine .ag-icon-aggregation {
--ag-icon-font-family: 'Material Design Icons';
--ag-icon-font-code-aggregation: '\F02C3';
font-weight: normal;
color: red;
}
英文:
Have a read of Ag-grid Custom Icon
You can use the custom icon font-family by inserting it in index.html
via a <link>
and importing it in custom.scss
.
Example
index.html
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"/>
custom.scss
.ag-theme-alpine {
--ag-icon-font-family: 'Font Awesome 5 Free';
--ag-icon-font-code-aggregation: '\f247';
--ag-icon-font-code-arrows: '\f0b2';
--ag-icon-font-code-asc: '\f062';
--ag-icon-font-code-cancel: '\f057';
--ag-icon-font-code-chart: '\f080';
--ag-icon-font-code-color-picker: '\f576';
--ag-icon-font-code-columns: '\f0db';
--ag-icon-font-code-contracted: '\f146';
--ag-icon-font-code-copy: '\f0c5';
--ag-icon-font-code-cross: '\f00d';
--ag-icon-font-code-desc: '\f063';
--ag-icon-font-code-expanded: '\f0fe';
--ag-icon-font-code-eye-slash: '\f070';
--ag-icon-font-code-eye: '\f06e';
--ag-icon-font-code-filter: '\f0b0';
--ag-icon-font-code-first: '\f100';
--ag-icon-font-code-grip: '\f58e';
--ag-icon-font-code-group: '\f5fd';
--ag-icon-font-code-last: '\f101';
--ag-icon-font-code-left: '\f060';
--ag-icon-font-code-linked: '\f0c1';
--ag-icon-font-code-loading: '\f110';
--ag-icon-font-code-maximize: '\f2d0';
--ag-icon-font-code-menu: '\f0c9';
--ag-icon-font-code-minimize: '\f2d1';
--ag-icon-font-code-next: '\f105';
--ag-icon-font-code-none: '\f338';
--ag-icon-font-code-not-allowed: '\f05e';
--ag-icon-font-code-paste: '\f0ea';
--ag-icon-font-code-pin: '\f276';
--ag-icon-font-code-pivot: '\f074';
--ag-icon-font-code-previous: '\f104';
--ag-icon-font-code-right: '\f061';
--ag-icon-font-code-save: '\f0c7';
--ag-icon-font-code-small-down: '\f107';
--ag-icon-font-code-small-left: '\f104';
--ag-icon-font-code-small-right: '\f105';
--ag-icon-font-code-small-up: '\f106';
--ag-icon-font-code-tick: '\f00c';
--ag-icon-font-code-tree-closed: '\f105';
--ag-icon-font-code-tree-indeterminate: '\f068';
--ag-icon-font-code-tree-open: '\f107';
--ag-icon-font-code-unlinked: '\f127';
--ag-icon-font-code-checkbox-checked: '\f00c';
--ag-icon-font-code-checkbox-unchecked: '\f00d';
}
.ag-theme-alpine .ag-icon,
.ag-theme-alpine .ag-checkbox-input-wrapper,
.ag-theme-alpine .ag-radio-button-input-wrapper {
/* Font Awesome requires bold on all icon elements */
font-weight: bold;
}
/* selectively replace the group and aggregation icons with Material Design Icons */
.ag-theme-alpine .ag-icon-group {
--ag-icon-font-family: 'Material Design Icons';
--ag-icon-font-code-group: '\F0328';
font-weight: normal;
color: red;
}
.ag-theme-alpine .ag-icon-aggregation {
--ag-icon-font-family: 'Material Design Icons';
--ag-icon-font-code-aggregation: '\F02C3';
font-weight: normal;
color: red;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论