Ahmer Khan
Ahmer Khan

Reputation: 767

Hide UI-Grid template based on condition in angular js 1

If field key i have Boolean value always. What I want is if the value is true show the cell template otherwise hide it.

columnDefs: [{
            displayName: 'Advanced',
            field: 'advanced',
            enableSorting: true,
            enableFiltering: true,
            enableColumnResizing: false,
            cellTemplate: 'scripts/components/profiles/tm/programs/datagrid/advancedCellTemplate.html',
            maxWidth: 108,
            filter: {
                type: uiGridConstants.filter.SELECT,
                selectOptions: controller.programsPackage
            }
        }]

Upvotes: 2

Views: 1290

Answers (2)

Nikolay Osaulenko
Nikolay Osaulenko

Reputation: 1482

You can use angular.extend or Object.assign like this

const fields = [angular.extend({}, {
   displayName: 'Advanced',
   field: 'advanced',
   enableSorting: true,
   enableFiltering: true,
   enableColumnResizing: false,
   maxWidth: 108,
   filter: {
      type: uiGridConstants.filter.SELECT,
     selectOptions: controller.programsPackage
   }
 }, field ? {
     cellTemplate:  'scripts/components/profiles/tm/programs/datagrid/advancedCellTemplate.html'
} : null)]

Upvotes: 1

Ahmer Khan
Ahmer Khan

Reputation: 767

I find out the solution very simple, i just need to add the condition to the cell template based on field advanced value

'<div ng-if="row.entity.advanced">'

Upvotes: 0

Related Questions