简体   繁体   中英

Using ember computed property(filter) to filter model and using ember-models-table 2 for displaying in table format. It gives no record to show

Trying to display user details using ember-models-table addon. Also wanted to filter the data using a isActive field .Am using ember computed property for that (filter). First time when the page is loading am getting the correct result.But when i try to filter , i could see value for currentfilter is passed correctly but am not getting any results. The table says no records to show.

My .hbs code:

    <div class="form-group">
        <label for="show">Show:</label>
        <select class="form-control" id="show" onchange={{action "filterUpdated" value="target.value"}}>
            <option value="null">All</option>
            <option value="true">Active</option>
            <option value="false">Inactive</option>
        </select>
    </div>

    {{models-table
data=filteredPeople 
columns=columns 
showColumnsDropdown=false 
useNumericPagination=true 
filteringIgnoreCase=true 
showPageSize=true
    }}

My controllers code:

 users: alias('model'),
currentFilter: null,

filteredPeople: filter('users', function(user) {

  if(this.get('currentFilter') === null) {
    return true;
  } else {
    return user.isActive === this.get('currentFilter');
  }
}).property('users', 'currentFilter'),

actions: {

  filterUpdated: function (value) {

    alert(value);
    if (value=== null) {
      this.set('currentFilter', null);
    }
    else {
      this.set('currentFilter', value);
    }
  }

Please help.

After checking , i just noted it was a silly mistake, the filterUpdated method returns string and isActive field needs a boolean value. I just included the follwing line to change it to boolean.

var isActiveS = (this.get('currentFilter') == 'true');

It worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM