3

I need to display the text in a cell as a link based on a status or as a plain text. If the status is 'Deleted' the name should be displayed as plain text or else as an hyperlink. Below are my grid options. I am always getting it as hyperlink. Someone please help me correct my cell template so that I am getting it correct.

$scope.gridOptions = {
    data: 'ProjectDetails',
    columnDefs: [
    { field: 'Id', displayName: 'ID', visible: false },
    { displayName: 'Name', width: 200, cellTemplate: '<div> {{row.entity.ProjectStatus}} != Deleted </div>' ? '<div><a href="http://################ID={{row.entity.Id}}">{{row.entity.Name}}</a></div>' : '<div> {{row.entity.Status}}</div>' },
    { field: 'Expense', displayName: 'Operating Expense', width: 185, cellFilter: 'noFractionCurrency' },        
    { field: 'Status', displayName: 'Status', width: 150 }
    ]
};
1
  • Why don't you accept your solution ? Commented Jul 7, 2016 at 2:22

3 Answers 3

2

ng-if helped me.

cellTemplate: "<a target='_blank' ng-if=\"row.entity.Status != 'Deleted'\" 
href='#########?ID={{row.entity.Id}}'>{{row.entity.Name}}</a><div ng-
if=\"row.entity.Status == 'Deleted'\">{{row.entity.Name}}</div>" 
Sign up to request clarification or add additional context in comments.

Comments

0

I'd do this with ngShow.

var cellTemplate = "<div ng-show='row.entity.Status !== 'Deleted''><a href='#####{{row.entity.Id}}'>{{row.entity.Name}}</a></div><div ng-show='row.entity.Status === 'Deleted''>{{row.entity.Status}}</div>"

3 Comments

That does not help. It shows both the Name both as the link and as the text in each row irrespective of the status.
It only displays a link if row.entity.Status !== 'Deleted'. Check your JSON. There are two div's using two distinct ng-show, modify them to fit your needs. Sorry for blind-coding errors.
Not sure still had no luck with ngShow.
0

I just added href for Status -deleted and plain text for non-deleted option.

var cellTemplate: "<a target='_blank' ng-if="row.entity.Status !=\ 'Deleted\'" 
href='#########>{{row.entity.Name}}</a><div ng-
if="row.entity.Status == \'Deleted\'">{{row.entity.Name}}</div>"

Comments

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.