Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript UI网格-如何使用selectAll复选框选择当前页面中显示的记录_Javascript_Angularjs_Ui Grid - Fatal编程技术网

Javascript UI网格-如何使用selectAll复选框选择当前页面中显示的记录

Javascript UI网格-如何使用selectAll复选框选择当前页面中显示的记录,javascript,angularjs,ui-grid,Javascript,Angularjs,Ui Grid,在UI网格中,选中“全选”复选框后,将选择当前页面以及其他页面中可见的所有记录 问题我们可以通过什么方式选择仅在当前页面中显示的行 普朗克 尝试了api$scope.gridApi.selection.selectAllVisibleRows()但它不选择仅在当前页面中显示的行。如果单击“选择可见行”按钮并移动到下一页,也会选择其中的记录 api的其他详细信息选择AllVisibleRows 在ui网格函数中选中时,选择AllVisibleRows。row.visible返回所有页面上所有行的

在UI网格中,选中“全选”复选框后,将选择当前页面以及其他页面中可见的所有记录

问题我们可以通过什么方式选择仅在当前页面中显示的行

普朗克

尝试了api
$scope.gridApi.selection.selectAllVisibleRows()但它不选择仅在当前页面中显示的行。如果单击“选择可见行”按钮并移动到下一页,也会选择其中的记录

api的其他详细信息
选择AllVisibleRows

在ui网格函数中选中时,选择AllVisibleRows。
row.visible
返回所有页面上所有行的
true



尝试使用进行循环以下是

要仅选择当前网格页面中的行,必须在注册其API时为ui网格v4.4.9 rowSelectionChangedBatch事件添加处理程序。方法。正如您所指出的,它认为所有未过滤的行都是可见的。它不排除当前网格页上未呈现的行。因此,我们不得不自己处理问题:

        onRegisterApi: function (gridApi) {

            gridApi.selection.on.rowSelectionChangedBatch(null, function (rows) {
                var grid = this.grid;
                // you'll need ui-grid v4.4.9 or better 
                // otherwise you'll need to invert getSelectAllState()
                // as explained at https://github.com/angular-ui/ui-grid/issues/5411
                var isAllSelected = grid.api.selection.getSelectAllState();
                // when select all is checked, the default behavior is to select all grid rows on all pages
                // so we have to deselect them all first before we select just the ones on the visible page
                grid.api.selection.clearSelectedRows(null);
                if (isAllSelected) {
                    // select only the rows displayed in the current grid page
                    var startIndex = (grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize;
                    var endIndex = startIndex + grid.options.paginationPageSize;
                    for (let i = startIndex; i < endIndex; i++) {
                        let row = grid.rows[i];
                        row.isSelected = true;
                    }
                }
            });
        },
onRegisterApi:函数(gridApi){ gridApi.selection.on.rowSelectionChangedBatch(空,函数(行){ var grid=this.grid; //您将需要ui grid v4.4.9或更高版本 //否则,您将需要反转getSelectAllState() //正如在https://github.com/angular-ui/ui-grid/issues/5411 var isAllSelected=grid.api.selection.getSelectAllState(); //选中“全选”时,默认行为是选择所有页面上的所有网格行 //因此,我们必须先取消选择所有选项,然后再选择可见页面上的选项 grid.api.selection.clearSelectedRows(null); 如果(全部选中){ //仅选择当前网格页面中显示的行 var startIndex=(grid.options.paginationCurrentPage-1)*grid.options.paginationPageSize; var endIndex=startIndex+grid.options.paginationPageSize; for(设i=startIndex;i
        onRegisterApi: function (gridApi) {

            gridApi.selection.on.rowSelectionChangedBatch(null, function (rows) {
                var grid = this.grid;
                // you'll need ui-grid v4.4.9 or better 
                // otherwise you'll need to invert getSelectAllState()
                // as explained at https://github.com/angular-ui/ui-grid/issues/5411
                var isAllSelected = grid.api.selection.getSelectAllState();
                // when select all is checked, the default behavior is to select all grid rows on all pages
                // so we have to deselect them all first before we select just the ones on the visible page
                grid.api.selection.clearSelectedRows(null);
                if (isAllSelected) {
                    // select only the rows displayed in the current grid page
                    var startIndex = (grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize;
                    var endIndex = startIndex + grid.options.paginationPageSize;
                    for (let i = startIndex; i < endIndex; i++) {
                        let row = grid.rows[i];
                        row.isSelected = true;
                    }
                }
            });
        },
onRegisterApi: function(gridApi) {
    gridApi.selection.on.rowSelectionChangedBatch($scope, function() {

        // check for ui-grid version to revert opposite value
        var isAllSelected = gridApi.selection.getSelectAllState();

        if (isAllSelected) { 

            // unselect all rows as select all button selects all rows by default
            gridApi.selection.clearSelectedRows();

            /* Will fetch only grid rows visible on page. It will fetch the correct 
               rows even if you have applied sorting, pagination and filters. */
            var gridRows = this.grid.getVisibleRows();


            // function to set Selected to only visible rows
            angular.forEach(gridRows, function(gridRow) { 
                gridRow.setSelected(true);
            });
        }
        $scope.selectedRows = gridApi.selection.getSelectedRows();
   });
}