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

If not has a initial sorting order and click header with MultiSortKey, the default sortList will be changed #138

Open
lijinpengFj opened this issue Apr 11, 2018 · 0 comments

Comments

@lijinpengFj
Copy link

hi, I use this plugin in my application and I find that if I call plugin without config 'sortList' , just like $("table").tablesorter({}), and then click header with MultiSortKey (like shift), $.tablesorter.defaults.sortList is changed to the be the current sort column's index and order.

In my application, I need to reset the table. So in this state if I do it, the table will have the default sort order. I think it's unexpected.

I check the code of plugin. In jquery.tablesorter.js L711, it call $.extend.

config = $.extend(this.config, $.tablesorter.defaults, settings);

if settings don't have a sorList, config.sortList will be $.tablesorter.defaults.sortList.

config.sortList == $.tablesorter.defaults.sortList
//is true

The reason are array is reference type and $.extend is not recursive by default , so they are the same reference, the same array, if change one, another one will be changed.

And in L778, config.sortList is changed and the default is changed too.

I think you can use $.extend with deep = true or give the settings.sortList a default value, an empty array to fix it.

Good Day! : )

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