🌐 AI搜索 & 代理 主页
Skip to content

Clicking on a sortable table column header not working (not sort) when 'sortable' value is dynamic #5520

@alfianwahid

Description

@alfianwahid

Describe the bug

Clicking on a sortable table column header not working (not sort) when 'sortable' value is dynamic.
Like example below when default fields no sortable or sortable is false, then switch enableSortAble to true, column header is changed (there are arrow sort icon) but clicking the header column is not sorting the column.

Steps to reproduce the bug

<template>
  <div>
    <b-form-checkbox switch v-model="enableSortAble">
      <span :class="enableSortAble ? 'font-weight-bold text-primary' : 'text-secondary'">Sortable</span>
    </b-form-checkbox>

    <b-table :items="items" :fields="fields" responsive="sm"></b-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      enableSortAble: false,
      fields: [
        { key: "last_name" },
        { key: "first_name" },
        { key: "age" },
        { key: "isActive" }
      ],
      items: [
        {
          isActive: true,
          age: 40,
          first_name: "Dickerson",
          last_name: "Macdonald"
        },
        { isActive: false, age: 21, first_name: "Larsen", last_name: "Shaw" },
        { isActive: false, age: 89, first_name: "Geneva", last_name: "Wilson" },
        { isActive: true, age: 38, first_name: "Jami", last_name: "Carney" }
      ]
    };
  },
  watch: {
    enableSortAble(newVal) {
      this.fields = this.fields.map(el => {
        return { ...el, sortable: newVal };
      });
    }
  }
};
</script>

Expected behavior

When click switch button to enable sortable, then clicking on a sortable column header will sort the column.

Versions

Libraries:

  • BootstrapVue: 2.15.0
  • Bootstrap: 4.5.0
  • Vue: 2.6.11

Environment:

  • OS: Windows 10
  • Browser: Chrome 83.0

Demo link

https://codesandbox.io/s/bvtable-sortable-g6lyz-g6lyz?file=/App.vue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions