coreui / coreui-free-vue-admin-template

Open source admin template based on Bootstrap 5 and Vue 3
https://coreui.io/product/free-vue-admin-template/
MIT License
3.3k stars 968 forks source link

Column filter inputs dissapear on no/empty results #229

Closed alexbernotas closed 4 years ago

alexbernotas commented 4 years ago

Every time there are no results after filtering the filter search/inputs disappear (that allows us to search through the table columns), the column structure remains intact but the filter disappears if the results are empty. There is no way to even undo the search. How can we make the filter inputs stay?

Table: node_modules/@coreui/vue/src/components/table/CDataTable.vue

"dependencies": {
    "@competitionlabs/javascript-sdk": "^1.0.0",
    "@coreui/coreui": "^3.2.2",
    "@coreui/icons": "^2.0.0-beta.3",
    "@coreui/utils": "^1.3.1",
    "@coreui/vue": "^3.1.1",
    "@coreui/vue-chartjs": "^1.0.5",
    "vue": "~2.6.11",
    "vue-router": "~3.3.4",
    "vuex": "~3.5.1"
  }

Example of our setup:

<CTableWrapper
:items="results"
:fields="fields"
:activeFields="activeFields"
:loading="loading"
hover
small
striped
border
fixed
caption="Products"
/>

export default {
  name: 'Tables',
  data() {
    return {
      fields: null,
      activeFields: null,
      results: null,
      loading: false,
      error: null,
      query: {},
      sortBy: null
    }
  },
  components: { CTableWrapper },
  mounted () {
    this.$root.$on('query-table', (e) => {

      for (var key in e) {
        if (e.hasOwnProperty(key) && e[key]) {
          this.query[key] = e[key];
        }else {
          delete this.query[key];
        }
      }
      this.queryData();
    });
  },
  created () {
    // fetch the data when the view is created
    this.fetchData()
  },
  methods: {
    fetchData ( skip ) {
      this.results = [
        {"id": "1", "name": "test"},
        {"id": "2", "name": "test2"}
      ]
    },
    queryData () {
      this.results = [];
      this.fields = Object.keys({"id": "1", "name": "test"}).concat(['actions'])
      if (this.activeFields == null) {
        this.activeFields = Object.keys({"id": "1", "name": "test"}).concat(['actions'])
      }
    }
  }
}
woothu commented 4 years ago

This bug is fixed in 3.1.2 version