简体   繁体   English

通过外部按钮刷新行数据时,取消选择Ag-Grid全选复选框

[英]Deselecting Ag-Grid select-all checkbox when the row data is refreshed via an outside button

I am using a normal ag-grid with checkboxes in the first row of the grid to allow a user to select a row. 我在网格的第一行中使用带有复选框的普通ag-grid,以允许用户选择一行。 I also have a select all checkbox in the header of the grid, which allows a user to easily select all checkboxes and rows with one click. 我还在网格标题中有一个“全选”复选框,这使用户可以一键轻松选择所有复选框和行。 I created the select-all checkbox with this code: 我使用以下代码创建了全选复选框:

ag-grid set the column header to be a checkbox,and do the select all or deselect all column,other than only groups ag-grid将列标题设置为复选框,然后执行“全选”或“取消全选”列,而不仅仅是组

My users would like the option to include a "Refresh Data" button on his or her own that would allow the user to refresh the data in the grid, essentially passing fresh row data into the component. 我的用户希望自己包括一个“刷新数据”按钮的选项,该按钮将允许用户刷新网格中的数据,实际上是将新的行数据传递到组件中。 It would only re-load the row data. 它只会重新加载行数据。 The problem here is that because it is only refreshing the row data, the select-all-checkbox stays checked while the rest of the rows are refreshed and un-checked. 这里的问题是,因为仅刷新行数据,所以全选复选框保持选中状态,而其余行被刷新和未选中。 Is there a way to un-check the select-all-checkbox in the header when the row data is refreshed? 当刷新行数据时,是否有一种方法可以取消选中标题中的全选复选框? Any event that can be listened to there? 有什么可以听的事件吗?

My grid with checkboxes looks really similar to this: https://cloud.githubusercontent.com/assets/4819263/7002796/abb1e6da-dc50-11e4-9fde-3abd8de19261.png 我的带有复选框的网格看起来确实与此类似: https : //cloud.githubusercontent.com/assets/4819263/7002796/abb1e6da-dc50-11e4-9fde-3abd8de19261.png

Thanks for any help 谢谢你的帮助

try to add id or ng-model to checkbox and after loading new data to grid using id check all checkbox true,check below code --- 尝试将id或ng-model添加到复选框,并在使用id将新数据加载到网格中后,选中所有复选框,请选中以下代码-

function selectAllRenderer(params) {
    $scope.selectAll=true;
    var cb = document.createElement('input');
    cb.setAttribute('type', 'checkbox');
    cb.setAttribute('id','selectAll');
    cb.setAttribute('ng-model','selectAll');
    cb.setAttribute('ng-click','selectAllCheckbox(selectAll)');

    var eHeader = document.createElement('label');
    eHeader.setAttribute("style","display:inline");
    var eTitle = document.createTextNode(params.colDef.headerName);
    eHeader.appendChild(cb);
    eHeader.appendChild(eTitle);

    cb.addEventListener('change', function () {
        if ($(this)[0].checked) {
            params.api.selectAll();
        } else {
            params.api.deselectAll();
        } 
    });
    return eHeader; 
}


$scope.selectAllCheckbox = function(checked){
    if(checked===true){
        $scope.selectAll = false;
    }else{
        $scope.selectAll=true;
    }
}

after loading grid data try to add below code-- 加载网格数据后,尝试添加以下代码-

j$('#selectAll').checked=true; j $('#selectAll')。checked = true;

or 要么

using angularjs there is ng-model and set true after loading data. 使用angularjs有ng-model并在加载数据后设置为true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM