asc and desc tags flipped unless default settings are manually defined
octalide opened this issue · 0 comments
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.