how to make row disabled with ag-grid?

后端 未结 1 641
情话喂你
情话喂你 2020-12-07 06:01

I work with ag-grid and i found how to make a column disabled in the doc (https://www.ag-grid.com/documentation-main/documentation.php) but after reading do

相关标签:
1条回答
  • 2020-12-07 06:37

    TL;DR

    There is no option in the library to make a single row disabled(both visually and keyboard event based), the only way we could make a single row disabled is by using a customCellRenderer for both header and subsequent cell checkboxes, this allows full control over the checkbox. Besides this, there are three other ways where you can disable ag-grid checkbox based on value,

    1)This is using checkBoxSelection param, it would empty the cell based on the condition.

    checkboxSelection = function(params) {
    
       if (params.data.yourProperty) {
          return true;
       }
       return false;
    }
    
    1. This would only disabled click events and style it accordingly,

    cellStyle: params => return params.data.status? {'pointer-events': 'none', opacity: '0.4' } : '';

    3)This would disable it completely, as you have control over the input, but you may have to use string literals,

    cellRenderer: (params) => {
           if (params.value) {
              return `<input type="checkbox" checked/>`;
           }
           else {
              return `<input type="checkbox" />`;
           }
     }
    

    You could use customCellRenderer(customCellRendererParams for props), headerCellRenderer(headerCellRendererParams for props) which accepts a complete JSX component.

    1. I think this would be the most helpful, it allows you to choose the cellRenderer component based on the row value for that column. Its very well described in the ag-grid documentation.
    0 讨论(0)
提交回复
热议问题