Giter Club home page Giter Club logo

Comments (7)

ratiw avatar ratiw commented on May 28, 2024

@tmikaeld Can you please explain more about this?

from vue-table.

tmikaeld avatar tmikaeld commented on May 28, 2024

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.

from vue-table.

ratiw avatar ratiw commented on May 28, 2024

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

from vue-table.

ratiw avatar ratiw commented on May 28, 2024

@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.

from vue-table.

tmikaeld avatar tmikaeld commented on May 28, 2024

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.

from vue-table.

ratiw avatar ratiw commented on May 28, 2024

@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.

from vue-table.

tmikaeld avatar tmikaeld commented on May 28, 2024

That's certainly more flexible, thanks!

from vue-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.