Skip to content

Commit abe45de

Browse files
committed
Add the JavaScript for sortable table rows
1 parent d418008 commit abe45de

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ end
2323
gem 'activeadmin-sortable'
2424
```
2525

26+
### Include the JavaScript in active_admin.js
27+
28+
```javascript
29+
//= require activeadmin-sortable
30+
```
31+
2632
### Configure your ActiveAdmin Resource
2733

2834
```ruby
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//= require jquery-ui
2+
3+
(function($) {
4+
$(document).ready(function() {
5+
$('.handle').closest('tbody').activeAdminSortable();
6+
});
7+
8+
$.fn.activeAdminSortable = function() {
9+
this.sortable({
10+
update: function(event, ui) {
11+
var url = ui.item.find('[data-sort-url]').data('sort-url');
12+
13+
$.ajax({
14+
url: url,
15+
type: 'post',
16+
data: { position: ui.item.index() + 1 },
17+
success: function() { window.location.reload() }
18+
});
19+
}
20+
});
21+
22+
this.disableSelection();
23+
}
24+
})(jQuery);

lib/activeadmin-sortable.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'activeadmin-sortable/version'
22
require 'activeadmin'
3+
require 'rails/engine'
34

45
module ActiveAdmin
56
module Sortable
@@ -22,8 +23,14 @@ def sortable_handle_column
2223
end
2324
end
2425
end
25-
end
2626

27-
::ActiveAdmin::ResourceDSL.send(:include, Sortable::ControllerActions)
28-
::ActiveAdmin::Views::TableFor.send(:include, Sortable::TableMethods)
27+
::ActiveAdmin::ResourceDSL.send(:include, ControllerActions)
28+
::ActiveAdmin::Views::TableFor.send(:include, TableMethods)
29+
30+
class Engine < ::Rails::Engine
31+
# Including an Engine tells Rails that this gem contains assets
32+
end
33+
end
2934
end
35+
36+

0 commit comments

Comments
 (0)