Vue-good-table: How to separate sorting from view?

Created on 1 Nov 2017  Â·  8Comments  Â·  Source: xaksis/vue-good-table

Hi, at first, thanks for this good plugin!

Is there way to separate sorting algoritm from view template? Few examples of problem
--- we have DESC id's of pages (201, 200, 107, 100, 99)
we want to show them like a links to pages 99
But after wrapping it becomes a string and sorting stop works as expected (like for integers).
DESC becomes (99, 201, 200, 107, 100)!! 200 between 90 and 100, because first chars

Another thing we have 3 strings "0_mustBeSecond", "1_mustBeFirst", "2_mustBethird"
If we sort it like strings "1_mustBeFirst" always will be on the middle.
In the life we meet with this, for example, when we have statuses like "Opened, Closed and Suspend". We have 20 rows for each, and 20 rows for page. If we press on column title for sorting by this column, we newer will see "Opened" rows, they alway would be on the second page


Imho, obvious solutin add custom sorting param. If we don't have it, we apply default sorting rules (strings, integers, dates). If we have this param we sort by it. Maybe adding custom sorting function would be a great solution https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

enhancement

All 8 comments

@Hellek good idea. I'll look into adding custom sort function.

Are there any plans on implementing custom sort per column? I really need this. If there is no work being done on this I will try myself but if someone working on this, I'd rather spend my time on other things.

Hi @eric-naguras This is in the plans, but I haven't started working on it yet. I will be very happy to review a PR if you want to work on it.

@xaksis I have never done a PR but I'm willing to try.
It would be nice to give something back.

I looked already in the sources how the clickrow is done.
I guess I need to do something simular except it should be a choice.
If no sort function is given as a prop, it should still do a regular sort.

Cheers,
Eric

On Mon, Jan 15, 2018 at 8:05 PM xaksis notifications@github.com wrote:

Hi @eric-naguras https://github.com/eric-naguras This is in the plans,
but I haven't started working on it yet. I will be very happy to review a
PR if you want to work on it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/xaksis/vue-good-table/issues/106#issuecomment-357677326,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABl8IUlFb0gj4z8mKQMj5HZVY_shakvdks5tK00GgaJpZM4QNmg9
.

@eric-naguras yeah! I know first PR is always a little nerve-wracking. You can try it, or if you want to wait till tonight, I'll take a look at it and if it's simple enough I'll implement it tonight.

@xaksis It will take a few days before I can start anyway.
So if you can take a look that would be great.
It’s only a pointer to a custom function, right?

On Mon, Jan 15, 2018 at 10:08 PM xaksis notifications@github.com wrote:

@eric-naguras https://github.com/eric-naguras yeah! I know first PR is
always a little nerve-wracking. You can try it, or if you want to wait till
tonight, I'll take a look at it and if it's simple enough I'll implement it
tonight.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/xaksis/vue-good-table/issues/106#issuecomment-357708706,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABl8IT1cSsuX1872-0kw4mE6m5VTVAfeks5tK2oIgaJpZM4QNmg9
.

@Hellek @eric-naguras this is now available in v1.19.0 you can provide your own custom function via sortFn column property. @eric-naguras feel free to take a look at the changelog to see how I did it.

closing.

@xaksis Thank you very much. I'll try it right away.
I did look at the change log already but need to play with the debugger a while to fully understand it.

I updated my tables to use the custom sort functions and it works great. :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dylanvanes picture dylanvanes  Â·  3Comments

enghelewa picture enghelewa  Â·  3Comments

dariagrudzien picture dariagrudzien  Â·  3Comments

sylvaincaillot picture sylvaincaillot  Â·  3Comments

jannishuebl picture jannishuebl  Â·  3Comments