how to show/hide columns in ng-grid based on conditions

8,071 views
Skip to first unread message

telagraphic

unread,
Jun 28, 2013, 2:10:35 PM6/28/13
to ang...@googlegroups.com
I'm trying to show/hide some columns in ng-grid based on which user is viewing the page.
The visible property doesn't take a function which returns a true or false boolean?

I thought it would, but it does not.  So then how would I hide/show based on certain conditions?

    $scope.gridOptions = {
        data: 'myData',
        canSelectRows: false,
        displaySelectionCheckbox: false,
        footerRowHeight: 35,
        showFooter: true,
        showGroupPanel: true,
        showColumnMenu: true,
        showFilter: true,
        enableColumnResize: true,
        sortInfo: { fields: ['SignupDate'], directions: ['asc'] },
        columnDefs: [
            { field: 'Account', displayName: 'Account Number', width: '160', visible: $scope.isUserAdmin() },
            { field: 'LineOfBusiness', displayName: 'Commodity Type', width: '130' }
        ]//,
        //plugins: [new ngGridCsvExportPlugin()]
    };

John Niedzwiecki

unread,
Sep 6, 2013, 9:52:06 AM9/6/13
to ang...@googlegroups.com
After defining your gridOptions, add this:

$scope.gridOptions.columnDefs[0].visible = $scope.isUserAdmin();

That should do the trick.

Sim Longdy

unread,
Jan 8, 2018, 10:31:28 AM1/8/18
to Angular and AngularJS discussion
how can I put condition in this columnDefs?
Reply all
Reply to author
Forward
0 new messages