代码之家  ›  专栏  ›  技术社区  ›  Chan Yoong Hon

AG-GRID无法将图标按钮添加到我的AG GRID中的AG GRID和multiselection复选框的每一行中

  •  2
  • Chan Yoong Hon  · 技术社区  · 5 年前

    在我的ag网格的每一行中。我需要添加角材料图标按钮在每一行的银网格。但是,结果只显示了文本按钮。它不会在我的ag网格中显示我的图标按钮。

    接下来,我需要在我的ag网格中有多个选择复选框。但是,在我的ag网格中,只能选择一行。如何在ag网格列表中实现多选择行。

    下面是我的源代码。

      constructor() { 
          this.gridOptions = <GridOptions>{
              paginationPageSize: 18,
              animateRows: true,
        };
          this.gridOptions.columnDefs = [
            {
                field: "",
                width: 110,
                checkboxSelection: true
            },
            {
                headerName: "Distributor Code",
                field: "dist_code",
                width: 330,
                sortingOrder: ["asc", "desc"]
            },
            {
                headerName: "Distributor Name",
                field: "dist_name",
                width: 330,
                sortingOrder: ["asc", "desc"]
            },
            {
                headerName: "Status",
                field: "status",
                width: 330,
                sortingOrder: ["asc", "desc"],
    
            },
            {
                field: "", 
                width: 110, 
                cellRenderer: function clickNextRendererFunc(){
                        return '<button mat-stroked-button><mat-icon>keyboard_arrow_right</mat-icon></button>';
                }
            }
        ];
        this.gridOptions.rowData = [
            {dist_code: 1, dist_name: "ABC Enterprise", status: "Inactive"},
            {dist_code: 2, dist_name: "Go Go Enterprise", status: "Active"},
            {dist_code: 3, dist_name: "Alibaba Enterprise", status: "Active"},
            {dist_code: 4, dist_name: "Silver Enterprise", status: "Active"},
            {dist_code: 5, dist_name: "George Enterprise", status: "Inactive"},
            {dist_code: 6, dist_name: "Kent Enterprise", status: "Active"},
            {dist_code: 7, dist_name: "NP Enterprise", status: "Active"},
            {dist_code: 8, dist_name: "ED Enterprise", status: "Inactive"},
            {dist_code: 9, dist_name: "DD Enterprise", status: "Active"},
            {dist_code: 10, dist_name: "DF Enterprise", status: "Active"},
            {dist_code: 11, dist_name: "JS Enterprise", status: "Active"},
            {dist_code: 12, dist_name: "JD Enterprise", status: "Inactive"},
            {dist_code: 13, dist_name: "KFC Enterprise", status: "Active"},
            {dist_code: 14, dist_name: "MCD Enterprise", status: "Inactive"},
            {dist_code: 15, dist_name: "AH Enterprise", status: "Active"},
            {dist_code: 16, dist_name: "PP Enterprise", status: "Active"},
            {dist_code: 17, dist_name: "KOH Enterprise", status: "Active"},
            {dist_code: 18, dist_name: "HH Enterprise", status: "Active"},
            {dist_code: 19, dist_name: "GG Enterprise", status: "Inactive"},
            {dist_code: 20, dist_name: "PP2 Enterprise", status: "Active"}
        ]
    
        }
    

    下面是我的打印屏幕 enter image description here

    2 回复  |  直到 5 年前
        1
  •  8
  •   Paritosh    5 年前

    这个问题有三个部分。

    ag-grid-angular rowSelection="multiple"

    2.启用选择复选框:

    保持 checkboxSelection: true 第一次 ColDef

    3.在每行中添加角度材质图标按钮

    你需要使用 cellRenderer 并为此返回html字符串。

    cellRenderer: (data) => {
        return `<mat-icon class="mat-icon material-icons mat-icon-no-color" role="img" aria-hidden="true">
           home</mat-icon>`;
    }
    

    自从 细胞渲染器 如果希望返回html字符串,则不应简单地提供 <mat-icon>home</mat-icon>

        2
  •  3
  •   Just code    5 年前

    this . 但是,当您要渲染材质组件时,仍然需要编译materialbutton。

    cellRendererFramework 并使用自定义组件, 创建名为 RedComponentComponent

    cellRendererFramework: RedComponentComponent,//your custom component
    

          {
            headerName: "Value",
            field: "value",
            cellRendererFramework: RedComponentComponent,
            width: 100
          },
    

    这个组件将有你的按钮代码,它将负责你的渲染。

    我完成了他们的演示,结果是 here 你可以看看。

        3
  •  1
  •   kumar chandraketu    4 年前

    尝试以下方法:

     cellRenderer: params => {
              let eIconGui = document.createElement('span');         
                return  eIconGui.innerHTML = '<em class="material-icons">arrow</em>'  + ' ' + params.data.value;          
            }