drvic10k / bootstrap-sortable

adding sorting ability to bootstrap table
MIT License
513 stars 131 forks source link

Inconsistency with the Ruby on Rails Turbolinks #57

Closed fschuindt closed 9 years ago

fschuindt commented 9 years ago

Guys, I am using bootstrap-sortable in my Rails 4 application which uses the Rails 4 Turbolinks (https://github.com/rails/turbolinks). The problem is that to the bootstrap-sortable work proper the page must be reloaded (browser refresh), what do not happen naturally when you are using turbolinks.

Turbolinks works by changing the page content and the page URL with Ajax, it's bind in every app url link.

Any tip?

drvic10k commented 9 years ago

the table is sorted on document.ready event, if you load the page using ajax, call $.bootstrapSortable(applyLast) after the content is loaded

fschuindt commented 9 years ago

Actually I am trying to figure out what's the applyLast you've cited. Like:

$(document).on('page:load', $.bootstrapSortable(applyLast));

What should I define as applyLast?

drvic10k commented 9 years ago

as the readme says: When you add table rows or whole table from client side, use $.bootstrapSortable(applyLast) function to add sortability to parts/tables that were not present at document.ready. Use optional paramater applyLast=true if you want to preserve the last used sorting.

fschuindt commented 9 years ago

I am trying $(document).on('page:load', $.bootstrapSortable(false)); and still not working. :(

drvic10k commented 9 years ago

the problem is, that when the page is loaded, your data is not there yet. you have to call $.bootstrapSortable(false) in the callback of your ajax request

sam0x17 commented 9 years ago

Also if you are using bootstrap-sortable with Ruby on Rails you may wish to consider using https://github.com/SamKelly/rails_bootstrap_sortable as it packages the most recent release of bootstrap-sortable into a gem. On Feb 3, 2015 12:09 PM, "Fernando Schuindt" notifications@github.com wrote:

Guys, I am using bootstrap-sortable in my Rails 4 application which uses the Rails 4 Turbolinks (https://github.com/rails/turbolinks). The problem is that to the bootstrap-sortable work proper the page must be reloaded (browser refresh), what do not happen naturally when you are using turbolinks.

Turbolinks works by changing the page content and the page URL with Ajax, it's bind in every app url link.

Any tip?

Reply to this email directly or view it on GitHub https://github.com/drvic10k/bootstrap-sortable/issues/57.

fschuindt commented 9 years ago

Great! @drvic10k The event 'page:load' that I was using is indeed a Turbolinks callback, but not the right one. Checking the proper Turbolinks documentation I found others events including 'page:change', that's the right one to use in this case.

So to fix that and call $.bootstrapSortable(); after the page appears, my approach looks like this:

var bootstrapSortableReSort;
bootstrapSortableReSort = function() {
  $.bootstrapSortable();
};

$(document).on('page:change', bootstrapSortableReSort);

Works fine.

@SamKelly I have tried to use your gem but I got some errors which I reported on your project's issues. Thank you. :)

I think I can close it now. Thank you for all the help, best regards.