如何在 ag-grid 加载后禁用按钮
How do i disable a button after ag-grid loads
我有一个多列的 ag 网格,ag 网格下方有几个按钮。在这里,根据我需要 disable/enable buttons.Is 列之一的 ag 网格值,使用事件侦听器或任何其他方法是否合适?
请大家帮帮我!!
使用 GridOptions
界面中的 onGridReady
,然后在调用时禁用按钮。
根据您的解释,这些按钮与列值相关 - 然后您可以在初始化 ag-grid 之前根据列单元格值(具有您使用调用 setRowData 函数的值的数组)禁用按钮。
如果您计划在网格内操作数据,这可能会有所不同 - 这将需要在其中一个触发器内创建回调函数:
- cellValueChanged
- rowValueChanged
- cellEditingStopped
更多信息请点击此处:Grid Events
根据您的意见 - cellRenderer
应该是满足您需求的相关解决方案。
您可能会使用如下所示的简单变量来指示当前状态:
$scope.previous_page_param = false; //or true regarding user's choice
这是渲染器:
cellRenderer: function(params) {
if ($scope.previous_page_param) {
return '<button type="button">Enabled</button>';
} else {
return '<button disabled type="button">Disabled</button>';
}
}
工作代码在这里:Example
我找到了上面的答案。
这可以使用以下代码片段完成
(firstDataRendered) ="firstDataRendered($event)"
上面的代码在 HTML 中,下面的代码在 component.ts
中
firstDataRendered(params){
this.params =params;
this.gridApi = params.api; // To access the grids API
this.gridColumnApi = params.columnApi;
if(this.getProducts().length == 1){
this.disableRefreshButtons = false;
}
}
谢谢大家的支持。
我有一个多列的 ag 网格,ag 网格下方有几个按钮。在这里,根据我需要 disable/enable buttons.Is 列之一的 ag 网格值,使用事件侦听器或任何其他方法是否合适?
请大家帮帮我!!
使用 GridOptions
界面中的 onGridReady
,然后在调用时禁用按钮。
根据您的解释,这些按钮与列值相关 - 然后您可以在初始化 ag-grid 之前根据列单元格值(具有您使用调用 setRowData 函数的值的数组)禁用按钮。
如果您计划在网格内操作数据,这可能会有所不同 - 这将需要在其中一个触发器内创建回调函数:
- cellValueChanged
- rowValueChanged
- cellEditingStopped
更多信息请点击此处:Grid Events
根据您的意见 - cellRenderer
应该是满足您需求的相关解决方案。
您可能会使用如下所示的简单变量来指示当前状态:
$scope.previous_page_param = false; //or true regarding user's choice
这是渲染器:
cellRenderer: function(params) {
if ($scope.previous_page_param) {
return '<button type="button">Enabled</button>';
} else {
return '<button disabled type="button">Disabled</button>';
}
}
工作代码在这里:Example
我找到了上面的答案。 这可以使用以下代码片段完成
(firstDataRendered) ="firstDataRendered($event)"
上面的代码在 HTML 中,下面的代码在 component.ts
中 firstDataRendered(params){
this.params =params;
this.gridApi = params.api; // To access the grids API
this.gridColumnApi = params.columnApi;
if(this.getProducts().length == 1){
this.disableRefreshButtons = false;
}
}
谢谢大家的支持。