0

The question is about VueJS Framework - Element: http://element.eleme.io

I have some table (el-table) who gets data from array:

<el-table :data="someData">
<el-table-column prop="id" label="№"></el-table-column>
<el-table-column prop="is_active" label="Active"></el-table-column>
</el-table>

axios get JSON from DB, the array looks like:

[
{
  "id":1,
  "is_active":0
},
{
  "id":2,
  "is_active":1
},{
  "id":3,
  "is_active":1
}
]

Anyone knows how to say Element table show only rows with property "is_active" eq 0 or 1 (or another condition)?

1
  • 1
    Why not filter the data before passing it to the component, e.g. using a computed property? Commented Jan 25, 2018 at 10:49

1 Answer 1

3

You could use a computed property filtering your array, such as :

computed: {
  filteredList() {
    if (this.someData) {
      return this.someData.filter(data => data && data.is_active);
    }
    return [];
  },
},

And then bind this filtered list to the component :

<el-table :data="filteredList">
Sign up to request clarification or add additional context in comments.

4 Comments

It should probably be if (this.someData && this.someData.length) in case someData has an initial value of [].
The filter method simply returns an empty array if the initial array is empty.
But it won't have to trigger array.filter().
You're right ! Sorry I didn't get your point in the first place.

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.