【问题标题】:Row selectable in ag-grid在 ag-grid 中可选择的行
【发布时间】:2020-05-25 20:30:54
【问题描述】:

作为标题,我想通过在 angularjs 中使用 ag-grid 使一行可以在某些条件下选择。

过去,我使用 ui-grid 及其属性“isRowSelectable”来制作。

$scope.options = {
    ...
    isRowSelectable:function(row){
    return row.entity.taskExecutionStatus===0?true:false;
  }
}

但是,ag-grid 不像 ui-grid 那样具有“isRowSelectable”属性。 我现在该如何解决?

【问题讨论】:

  • 寻求帮助的问题必须包括期望的行为特定问题或错误以及重现所需的最短代码在问题本身。没有明确的问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Complete, and Verifiable example
  • 谢谢,我重新编辑了问题

标签: ag-grid


【解决方案1】:

gridOptions.onSelectionChanged() 函数中检查该行是否可选。 如果为false,则使用node.setSelected(false, false, true)取消选择该行;

【讨论】:

    【解决方案2】:

    当您不希望所有行都可选择时,一个有效的解决方案是使用复选框选择,如下所示:

    $scope.options = {
      columnDefs: [
        {headerName: "",
          width: 17,
          cellStyle: {'padding': '2px'},
          checkboxSelection: function(row){
            return row.entity.taskExecutionStatus===0?true:false;
          }
        },
        ...
      ],
      ...
      rowSelection: 'single', // or 'multiple'
      suppressRowClickSelection: true,
      ...
    };
    

    【讨论】:

      【解决方案3】:

      在 ag-grid 中选择单行:

       $scope.Gridoptions:{
          columnDefs:...,
      
          rowData:...,
      
            onRowClicked: RowClick,
      
           rowSelection: 'single',
      
          };
      
       function RowClick(param) {
      
          //To Find CurrentRow Index  
          var currentRowIndex = param.rowIndex;
      
          //GridData
      
          var gridData = $scope.gridOptionsInstrumentRegister.rowData;
      
          //Item ShowS RoWData
      
          var Item = params.data;
      
          }
      

      【讨论】:

        【解决方案4】:
        checkboxSelection: function (params) {
              params.node.selectable = false; // this will explicitly restrict to select (useful in select all)
              return true/false; // this will show or hide the checkbox
        }
        

        【讨论】:

        • 通常只有代码的答案没有那么有用 - 你应该解释一下这段代码是如何工作的。
        猜你喜欢
        • 2018-10-27
        • 2015-12-31
        • 2020-11-04
        • 2020-03-27
        • 1970-01-01
        • 2020-07-20
        • 2018-04-10
        • 2018-09-18
        • 2020-08-24
        相关资源
        最近更新 更多