Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Last active December 19, 2015 04:59
Show Gist options
  • Save telagraphic/5901394 to your computer and use it in GitHub Desktop.
Save telagraphic/5901394 to your computer and use it in GitHub Desktop.
A user fills in a search form and the grid gets populated based on their input. Depending on their role, certain columns should be hidden. The issue is that $scope.gridOptions is initially loaded upon page load and the code below doesn't update the grid when I have removed column from the columnsDefs array in the gridOptions object. I haven't f…
$scope.getBrokerSales = function () {
var searchCriteria = {
....
};
BrokerSalesService.executeBrokerSalesSearch(searchCriteria).then(function (data) {
resetColumnDefs();
$scope.brokerSaleResults = data.BrokerSaleResults;
});
};
function resetColumnDefs() {
if (userRole != Admin) {
$scope.gridOptions.columnDefs.splice(5, 1);
}
}
$scope.gridOptions = {
data: 'brokerSaleResults',
canSelectRows: false,
displaySelectionCheckbox: false,
footerRowHeight: 35,
showFooter: true,
showGroupPanel: true,
showColumnMenu: true,
showFilter: true,
enableColumnResize: true,
sortInfo: { fields: ['SignupDate'], directions: ['asc'] },
columnDefs: [
{ field: 'Broker', displayName: 'Broker', width: '120' },
{ field: 'AgentName', displayName: 'Agent Name', width: '120' },
{ field: 'AgentCode', displayName: 'Agent Code', width: '120' },
{ field: 'ConfirmationNumber', displayName: 'Confirmation #', width: '120' },
{ field: 'AccountType', displayName: 'Account Type', width: '110' },
{ field: 'AccountNumber', displayName: 'Account Number', width: '160' }
]
};
@callmekatootie
Copy link

Why don't you conditionally display the ng-grid say using ng-switch? As in, when the page loads, set the when clause to "false". Once you are certain of the type of the user, set it to true - since you are using ng-switch I expect that the ng-grid directive is not compiled until the when clause becomes true... Does that make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment