czwartek, 16 września 2010

Sequence Plugin

Very nice plugin for keeping table elements in order has been presented here
http://www.neilcrookes.com/2009/02/09/cakephp-sequence-behavior/
To fix the problem with 0-position element movement i slightly changed jquery script provided by Neil

<script type="text/javascript">
$(document).ready(function() {
  $("div.index table ").tableDnD({
    url: "<?php echo Router::url(array('action' => 'save_order')); ?>",
    originalOrder: null,
    onDragClass: "myDragClass",
    onDragStart: function(table, row) {
//        alert(originalOrder);
      originalOrder = jQuery.inArray(row, $(".dragMe", table));
    },
    onDrop: function(table, row) {
      var newOrder = jQuery.inArray(row, $(".dragMe", table));
      if (newOrder != originalOrder) {
        $.post(this.url+'/'+row.id, { 'data[<?php echo Inflector::singularize($this->name); ?>][weight]': newOrder });
      }
    },
  });
});
</script>
and little change in baked index function (just after foreach):
        $class = ' class="dragMe"';
        if ($i++ % 2 == 0) {
            $class = ' class="altrow dragMe"';
        }

Brak komentarzy:

Prześlij komentarz