4

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..

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:

    $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
  • Hi, did you manage to find a solution for this? Im having the same issue. The push solution also overwrites the other columns displaying only the 'newCol' Commented Apr 11, 2018 at 8:58

1 Answer 1

0

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

$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

Sign up to request clarification or add additional context in comments.

8 Comments

I have query about this.will it overwrite the ui-grid..and display only 'newcol' instead of apppending new column to the existing ui-grid..can you tell me..
hi,S.Baggy i tried it ..but it overwrites the existing columns in the ui-grid only shows the new one..
Can you paste in the code you used to add the columns?
i pasted the code i have slight change in requirement is it posssible to bind array in field of columnDefs.I have array of dates and i have bind it to field so that for each date column will be created. i have made some changes in code
In your original code, you set the columnDefs to [] (empty array), so I am not sure how you are overwriting existing columns, because it doesn't look like there are any? Maybe some more code is missing? If you could create a Plunker, it would make things a lot easier, if you have the time.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.