lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 513 forks source link

st-search on select tag not working on initial value #819

Open IngoVals opened 6 years ago

IngoVals commented 6 years ago

I'm using a select as a filter for a Smart-table. It is a simple filter and shows rows based on status. The initial value of the filter should show rows that have status Active but it seems that st-search doesn't get implemented until the first time it is changed, so on initial load no filtering is done.

Is it something I'm doing wrong or is there a simple workaround I'm missing?

See this plunker for an example of this

    <select st-search="status" st-delay="0">
      <option ng-repeat="f in statusOptions" ng-selected="f.code == 'Active'"
                    value="{{f.code}}">{{f.text}}</option>
    </select>
    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Status</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="row in collection | orderBy: 'status'">
          <td>{{row.name}}</td>
          <td>{{row.status}}</td>
        </tr>
      </tbody>
    </table>
  </section>
$scope.statusOptions = [
  { 'text': 'Everything', 'code': ''},
  { 'text': 'Active', 'code': 'Active' },
  { 'text': 'Cancelled', 'code': 'Cancelled'},
  { 'text': 'Expired','code': 'Expired' },
  { 'text': 'Waiting', 'code': 'Waiting'}
]

Using angular 1.6.4 Smart-table 2.1.8

lorenzofox3 commented 6 years ago

It seems that the value of option set with ng-selected does not trigger the input or change event in the first place. You could wrap you select in its own directive and make set the initial value so the event is triggered