angular js动态地将列添加到ui-grid

时间:2022-04-26 19:44:49

hi, I am developing angular js application In which i am using angular ui-grid to display bind the data coming from mvc controller.But after i bind data to ui-grid i want to add extra column to grid having buttons on each row dynamically.I dont know how to do it.Any help will be grateful..

嗨,我正在开发角度js应用程序我正在使用角度ui-grid来显示绑定来自mvc控制器的数据。但是在我将数据绑定到ui-grid之后我想要添加额外的列到网格上每行都有按钮我不知道怎么做。任何帮助都会感激不尽..

code: Here columnDefs will be binded to http service method that will call mvc controll action and bind response.I want to add new column now.That will have buttons for each row.Is there any to bind array to field of columnDefs:

代码:这里columnDefs将被绑定到http服务方法,它将调用mvc controll动作并绑定response.I想现在添加新列。每行都有按钮。是否有任何绑定数组到columnDefs的字段:

    $scope.gridOptions = {
            enableColumnsResize: true,
            enableSorting: false,
            enableFiltering: false,
            autoResize: true,
            enableFocusedCellEdit: true,
            enableCellSelection: true,
            enableCellEditOnFocus: true,
            enableColumnMenus: false,
            columnDefs: [

            ],
            data:$scope.swap,
            onRegisterApi: function (gridApi) {
                $scope.grid1Api = gridApi;
            }

        };
$http.get('/Default1/GetJsonData')
            .success(function (result) {
                $scope.swap = result;
                $scope.gridOptions.push({name:'newcol',filter:'newcolarray'})

                $scope.gridOptions.data = $scope.swap;
                console.log(result);
            })
            .error(function (data) {
                console.log(data);
            });

1 个解决方案

#1


0  

You should be able to do the following in your success() handler

您应该能够在success()处理程序中执行以下操作

$scope.gridOptions.columnDefs.push({name: 'newCol', displayName: 'My new col'});

And so on, one call like that per column, before you set $scope.gridOptions.data

依此类推,在设置$ scope.gridOptions.data之前,每列调用一次

#1


0  

You should be able to do the following in your success() handler

您应该能够在success()处理程序中执行以下操作

$scope.gridOptions.columnDefs.push({name: 'newCol', displayName: 'My new col'});

And so on, one call like that per column, before you set $scope.gridOptions.data

依此类推,在设置$ scope.gridOptions.data之前,每列调用一次