Saturday, February 1, 2014

Re: jQuery sortable: how to update database?

Ow yes, you've got me on the right way! I've changed my .ctp file now:

<script>
    $(function() {
        $('.sortable tbody').sortable({
            axis: 'y',
            scroll: true,
            opacity: 0.5,
            revert: 100,
            cursor: 's-resize',
            items: 'tr.grab',
            
            // volledige breedte van <tr> behouden
            
            helper: function (e, ui) {
                ui.children().each(function () {
                    $(this).width($(this).width());
                });
                return ui;
            },
            stop: function (event, ui) {
                var data = $(this).sortable('serialize');
                
                // POST naar server ($.post of $.ajax)
                
                $.ajax({
                    data: data,
                    type: 'POST',
                    url: '<?php echo $this->here; ?>'
                });
            }
        }).disableSelection();
    });
</script>

Then, I'll check on a submitted POST in my sort action and will handle the update.

One additional thing: where in Chrome developer tools can you see those ajax values? Elements, Network, Sources, ...? ;)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: