【问题标题】:ag-grid header checkbox selecting all the rows even the row that doesn't has the checkboxag-grid 标题复选框选择所有行,即使是没有复选框的行
【发布时间】:2019-03-16 13:40:21
【问题描述】:

我已经实现了一个网格,其中包含除最后一行之外的第一列带有复选框的行(即,最后一行没有任何复选框)。

const colDef = { 
        headerCheckboxSelection: this.forCheckbox,
        checkboxSelection: this.forCheckbox
 }

forCheckbox(params) {
    const displayedColumns = params.columnApi.getAllDisplayedColumns();
    if (params.node) {
        return (displayedColumns[0] === params.column  &&(params.node.data.myColNameValue !== '');
    }
    return (displayedColumns[0] === params.column);
}

所以myColNameValue 是'' 仅适用于最后一行。由于这种情况,网格的最后一行不会有复选框。但是,当我单击标题复选框时,它会检查并选择所有行以及最后一行,即使它没有复选框。

【问题讨论】:

标签: reactjs ag-grid


【解决方案1】:

实现 isRowSelectable() 函数,对不想被选中的行返回 false

请看这里 - https://www.ag-grid.com/javascript-grid-selection/#selectable-rows-with-header-checkbox

在下面的代码(ag-grid Javascript)中,只有年份

constructor(private http: HttpClient) {
    this.columnDefs = [
      {
        headerName: "Athlete",
        field: "athlete"
      },
      {
        headerName: "Age",
        field: "age"
      },
      {
        headerName: "Country",
        field: "country",
        headerCheckboxSelection: true,
        checkboxSelection: true
      },
      {
        headerName: "Year",
        field: "year"
      },
      {
        headerName: "Date",
        field: "date"
      },
      {
        headerName: "Sport",
        field: "sport"
      },
      {
        headerName: "Gold",
        field: "gold"
      },
      {
        headerName: "Silver",
        field: "silver"
      },
      {
        headerName: "Bronze",
        field: "bronze"
      },
      {
        headerName: "Total",
        field: "total"
      }
    ];
    this.rowSelection = "multiple";
    this.isRowSelectable = function(rowNode) {
      return rowNode.data ? rowNode.data.year < 2007 : false;
    };
    this.defaultColDef = { width: 200 };
  }

【讨论】:

  • 我也试过这个。 ` this.isRowSelectable = function(rowNode) { return false; `此函数为每一行返回false,但当我检查标题复选框时它仍然选择所有行。我还在&lt;AgGridReact&gt; 中将它作为道具传递为` ` ``
  • 这听起来像是正确的答案,我建议您升级到最新的 ag-grid 版本或以其他方式发布一个 plunker
猜你喜欢
  • 2019-04-22
  • 2020-09-23
  • 2020-12-10
  • 2016-01-21
  • 2014-06-20
  • 2017-03-20
  • 1970-01-01
  • 2018-05-20
  • 2022-12-05
相关资源
最近更新 更多