Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting and | for sort order. #55

Closed
tmikaeld opened this issue Jul 27, 2016 · 7 comments
Closed

Sorting and | for sort order. #55

tmikaeld opened this issue Jul 27, 2016 · 7 comments

Comments

@tmikaeld
Copy link

My API doesn't use | seperator for sort order, this should be an option not a requirement (It's added even if direction: '' is empty.

@ratiw
Copy link
Owner

ratiw commented Jul 27, 2016

@tmikaeld Can you please explain more about this?

@tmikaeld
Copy link
Author

If i set:
:sort-order="[{ field: 'id', direction: '' }]"
or:
:sort-order="[{ field: 'id' }]"

I will get ?id=|

While in the API I'm consuming, sort order is defined with -id for descending and id for ascending. Not sure how to accomplish that without changing the library code.

@ratiw
Copy link
Owner

ratiw commented Jul 27, 2016

@tmikaeld OK. I think of something and let you know. May not be tonight though.

@ratiw
Copy link
Owner

ratiw commented Jul 29, 2016

@tmikaeld What I would do is to modify getSortParam() a bit that it will check if there is getSortParam() method in its parent instance. And if there is, it will call the method (with the sortOrder as its argument) on the parent instance instead of using the default one.

So, you could effectively override how the sort parameter would be constructed before sending it to the server in the loadData().

This way I don't have to introduce another prop.

@tmikaeld
Copy link
Author

tmikaeld commented Jul 29, 2016

This was the best i could come up with without creating a new prop.

With this you just set seperator: '+-' in the :sort-order prop object.

:sort-order="[{ field: 'id', direction: 'desc', seperator: '+-' }]"

The change in vue-table.js, from line 661:

        getSortParam: function getSortParam() {
            if (!this.sortOrder || this.sortOrder.field == '') {
                return '';
            }

            var result = '';

            for (var i = 0; i < this.sortOrder.length; i++) {
                var fieldName = typeof this.sortOrder[i].sortField === 'undefined' ? this.sortOrder[i].field : this.sortOrder[i].sortField;

                console.log(this.sortOrder[i].seperator)

                //Support for -fieldName fieldName as ascending/descending sort order instead of fieldName|desc fieldName|asc
                if(!this.sortOrder[i].seperator == '+-') {
                  result += fieldName + '|' + this.sortOrder[i].direction + (i + 1 < this.sortOrder.length ? ',' : '');
                } else {
                  if(this.sortOrder[i].direction == 'asc') {
                    result += fieldName.replace('-','') + (i + 1 < this.sortOrder.length ? ',' : '');
                  } else {
                    result += '-'+fieldName.replace('-','') + (i + 1 < this.sortOrder.length ? ',' : '');
                  }

                }

            }

            return result;
        },

Let me know if it's good enough to include to the library.

@ratiw
Copy link
Owner

ratiw commented Jul 30, 2016

@tmikaeld FYI. No new prop is needed. I just don't have time for the documentation right now, sorry.

this is now in develop branch.

this is the example for Semantic UI.

And this is for Bootstrap.

@tmikaeld
Copy link
Author

That's certainly more flexible, thanks!

@ratiw ratiw closed this as completed Aug 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants