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

asc and desc tags flipped unless default settings are manually defined #42

Open
octalide opened this issue Jun 21, 2018 · 0 comments
Open

Comments

@octalide
Copy link

I'm attempting to sort a single column in descending order when the page loads. I noticed that unless I manually define $.tablesort.defaults, asc and desc in $.tablesort.settings are reversed from what they should be.
Here's what my init code looks like:

$(document).ready(function () {
    $('.ui.table.sortable').tablesort();
    $('#main_table').data('tablesort').sort($('#default_sort'), 'desc');
});

Here's console output that shows the "flip" when you don't set the default values:

var ts = $('#main_table').data('tablesort');
ts = {
   [functions]: ,
   $sortCells: { },
   $table: { },
   $th: null,
   $thead: { },
   __proto__: { },
   direction: "desc",
   index: null,
   settings: {
      [functions]: ,
      __proto__: { },
      asc: "sorted descending",
      debug: true,
      desc: "sorted ascending"
   }
}

Note asc: "sorted descending" and desc: "sorted ascending:".
Now, if I include the following in my <script> tag, asc and desc are set to what they should be:

$.tablesort.defaults = {
    debug: true,
    asc: 'sorted ascending',
    desc: 'sorted descending',
    compare: function (a, b) {
        if (a > b) {
            return 1;
        } else if (a < b) {
            return -1;
        } else {
             return 0;
        }
    }
};

Note that this is a direct copy and paste from the source code (aside from debug).
Additionally, I noticed that changing the values in $.tablesort.defaults in the source file doesn't change $.tablesort.settings like it should. I'm not setting the defaults anywhere else in my code.
I've been trying to figure out what is overwriting the default settings, but for the life of me I can't figure it out.

This might just be me doing something incorrectly, or missing some sort of cached data, but I don't think that's happening.

I'm fine with setting the defaults in my <script> tag as a work-around, but this basic function SHOULD work. No idea why it's not. I'd love for someone to take a look.

@octalide octalide changed the title asc and desc tags flipped unless default settings are manually defined asc and desc tags flipped unless default settings are manually defined Jun 21, 2018
@octalide octalide changed the title asc and desc tags flipped unless default settings are manually defined asc and desc tags flipped unless default settings are manually defined Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant