Vue-good-table: Bug in sorting related to initialSortBy

Created on 12 Oct 2018  路  8Comments  路  Source: xaksis/vue-good-table

Issue Type

  • [x] Bug

Specs

What version are you using?
2.15.0

What browser?
Chrome 69.0.3497.100, Safari 12.0

Expected Behavior

Sort changes when clicking on column headers

Actual Behavior

Sort does not change

Steps to Reproduce the Problem

https://jsfiddle.net/gira82/cq4etkp6/1/

Basically I need to have an array of ids related to selected rows.
So I have a selectionChanged method that reduce the rows selected to an array of ids.

In the fiddle I attached there are three things that make the sort working:

  1. Do not render selectedIds array in the template (comment out line 2 of html)
  2. Do not update selectedIds in the vue model (comment out line 99 of js)
  3. Remove the option "initialSortBy: {field: 'name', type: 'asc'}" from the options.

I think there is something not working properly in the sorting code.

Thank you

bug

All 8 comments

you need to take care of the 0 length case when sort is changed:
This will make your jsfiddle work.

selectionChanged(params) {
        /* console.log(params) */;
      if (!params.selectedRows.length) {
        this.selectedIds = [];
        return;
      } 
      const selectedIds = params.selectedRows.reduce((acc, row) => {
        acc.push(row.id)
        return acc
      }, [])
      console.log(selectedIds);
      this.selectedIds = selectedIds
    }

closing.

Sorry, but the .reduce correctly returns an empty array when params.selectedRows is empty.
In my humble opinion, the point is not this, and the sort is still not working in the updated fiddle: https://jsfiddle.net/gira82/cq4etkp6/18/

I carefully debug the problem before I opened the issue, and I cannot see any problem in this simple code.
It's curious that removing initialSortBy all starts to work.
I can make more tests if needed.

apologies for the initial haste, I'll re-open this. However if i comment out this.selectedIds assignment... everything seems to be working fine. I'll debug it more.

looks like if I don't print out {{ selectedIds }} , everything is working as well. strange.

Yes, as I wrote at the beginning, three things will make the script work:

  1. Do not render (or use in any way) selectedIds array in the template
  2. Do not update selectedIds array at the end of the method
  3. Remove the option "initialSortBy: {field: 'name', type: 'asc'}" from the options.

1 and 2 sound inexplicable to me (after about 2 years of Vue developing)

If you look at console, it seems that the method is triggered three times every time you change sorting.
Hope this will help.

so just published 2.15.2 and seems to have passed all my tests... I'm going to keep this open for a bit so we can test with your jsfiddle

ok tested with your fiddle... seems to be working well now. Thanks for reporting this!

Thank you to you for so fast fix! 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oflittlemother picture oflittlemother  路  6Comments

davidohlin picture davidohlin  路  6Comments

unixconky picture unixconky  路  4Comments

hoanghiep1x0 picture hoanghiep1x0  路  5Comments

dariagrudzien picture dariagrudzien  路  3Comments