Rahul Popuri
Rahul Popuri

Reputation: 79

Dropdown column in smart-table (angularjs)

I need to configure one of the columns in my smart-table to be a dropdown. The possible values for the 'Status' column are OK and PENDING. (These values are retrieved from a rest api) I am looking to initialize the value in the dropdown to OK/PENDING based on the value retrieved from the api.

I posted what I've tried so far,the status are all set to OK regardless of the actual value.

I'm just starting out with smart-table and javascript so any help is appreciated.

For reference, here is a sample json object being returned from my rest api (other fields removed):

[
 {
   comments: [
   {
     comment: "Test comment",
     userId: "test_user",
     timestamp: 1473282222280
   }
  ],
  status: "PENDING"
}]

Here is the smart-table html code:

  <tbody>
     <tr ng-repeat="row in rowCollection" ng-class="{danger: (row.status=='PENDING'),success:(row.status=='OK')}">
        <td cs-select="row"></td>
        <td align="center">
        <select st-search="status">
           <option value="">OK</option>
           <option value="">PENDING</option>
           <!-- <option ng-repeat="row in rowCollection | unique:'status'" value="{{row.status}}">{{row.status}}</option> -->
        </select></td>
        <td align="center">{{row.comments[0].comment}}</td>
  </tbody>

and a screenshot of the table: Screenshot

Upvotes: 0

Views: 1607

Answers (1)

Andre.Anzi
Andre.Anzi

Reputation: 151

You can try with the ng-selected directive in this way:

<select>
 <option ng-selected="row.status == 'PENDING'">PENDING</option>
 <option ng-selected="row.status == 'OK'">OK</option>
</select>

Upvotes: 1

Related Questions