Use Behavior to make table draggable on Ajax refresh
[order_line_extra.git] / item_schedule.php
index 45bbfd60a07a96e183c5c18dcb2774efaf17b9b5..e5115b12014ff883f6d0b74a2e678cbea11ad973 100644 (file)
@@ -122,16 +122,22 @@ tr.tDnD_whileDrag :nth-child(4), tr.tDnD_whileDrag :nth-child(5) {
 <script src="js/jquery.tablednd.0.8.min.js"></script>
 <script text="text/javascript">
        console.log('hello')
-       $(document).ready(function() {
-               console.log('ready')
-               $('#item_schedule table').tableDnD({
-                       onDragStart: function (table, row) {
-                                       console.log(table)
-                                       console.log(row)}
-                       ,onDrop: function (table, row) {
-                                       console.log(table)
-                                       console.log(row)}
-               })
+       /**  add table DnD as behavior **/
+       function onDragStart (table, row) {
+       console.log(table)
+               console.log(row)
        }
-       )
+       function onDrop(table, row) {
+                       console.log(table)
+                       console.log(row)
+       }
+
+       var inserts = {
+               '#item_schedule table': function (e) { 
+                       // We can't use e directly because we need a JQUery Object to call tableDnD
+
+                       $('#item_schedule table').tableDnD({onDragStart: onDragStart, onDrop: onDrop})
+               }
+       }
+Behaviour.register(inserts);
 </script>