角ui网格:将选定单元格的值添加到模型中

时间:2021-11-24 04:54:17

I currently have a grid that I created with Angular ui-grid that allows the user to select a number of rows. The first column of each row has an id number, and I would like to add the ids of the selected rows to an object in my model so that I can use those ids to query my database on the back end.

我目前创建了一个网格,它具有角度ui网格,允许用户选择一些行。每一行的第一列都有一个id号,我想将所选行的id添加到模型中的一个对象中,以便使用这些id在后端查询我的数据库。

My problem is that I have not figured out how to access cell values, much less how to add the value of selected cells to my model. So any help would be very much appreciated!

我的问题是,我还没有找到如何访问单元格值的方法,更不用说如何向我的模型中添加所选单元格的值了。因此,我们非常感谢您的帮助!

Here is the code for my grid that I use in my controller

这是我在控制器中使用的网格的代码。

        $scope.gridOptions = {
        enablePaginationControls: false,
        enableRowSelection: true,
        enableSelectAll: true,
        paginationPageSize: 25,
        enableHorizontalScrollbar: 0,
        enableVerticalScrollbar: 0,
        columnDefs: [
            {field: 'analysis_id',displayName: 'Analysis ID',width: '15%'}, 
            {field: 'study_id', displayName: 'Study ID',width: '15%'},
            {field: 'publisher', displayName: 'Publisher',cellFilter: 'titlecase',width: '20%'},
            {field: 'parent_company', displayName: 'Parent Company', cellFilter: 'titlecase',width: '30%'}
        ]};

    $scope.gridOptions.onRegisterApi = function(gridApi) {
        $scope.gridApi = gridApi;
    };

2 个解决方案

#1


1  

Try

试一试

$scope.gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol) {               
    console.log($scope.gridApi.grid.getCellValue(newRowCol.row,newRowCol.col));
});

#2


1  

Maybe gridApi.selection.getSelectedRows(); is something you need.

也许gridApi.selection.getSelectedRows();是你需要的东西。

( ['ui.grid.selection'] dependence in app.module required)

([ui.grid。选择']依赖于app.module

$scope.gridOptions.onRegisterApi = function(gridApi){

    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope,function(row){
        $scope.selectedObject = gridApi.selection.getSelectedRows();
        console.log ($scope.selectedObject);
    });
};

#1


1  

Try

试一试

$scope.gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol) {               
    console.log($scope.gridApi.grid.getCellValue(newRowCol.row,newRowCol.col));
});

#2


1  

Maybe gridApi.selection.getSelectedRows(); is something you need.

也许gridApi.selection.getSelectedRows();是你需要的东西。

( ['ui.grid.selection'] dependence in app.module required)

([ui.grid。选择']依赖于app.module

$scope.gridOptions.onRegisterApi = function(gridApi){

    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope,function(row){
        $scope.selectedObject = gridApi.selection.getSelectedRows();
        console.log ($scope.selectedObject);
    });
};