mercredi 27 juin 2018

jQuery Sortable - Upon Creation

Upon creation of the sortable/portlets I need to set the position based on what is saved from within my database. So my question is how would one achieve such task?

I have the following to update the position(s) when a user selects their preference with the following and I know there is a create method on the sortable class, but just not sure how to get the positions to show from the database.

$( ".column" ).sortable({
        connectWith: ".column",
        handle: ".portlet-header",
        cancel: ".portlet-toggle",
        placeholder: "portlet-placeholder ui-corner-all",

        update: function(event, ui) {

            // identify handle for item
            var handle = ui.item.find(".portlet-header");

            // get current html of handle
            var html = handle.html();

            // update handle icon
            //handle.html('<i class="fa fa-cog fa-spin fa-fw"></i>');

            var data = $('.column').sortable( "serialize", { attribute: "sort" } );

            // ajax call
            $.ajax({
                url:        '/api/portlets/update',
                data:       { position: ui.item.index() },
                type:       'POST',
                success: function(response, ui) {

                    console.log('Success ' + response);
                    //handle.html("<span class='ui-icon ui-icon-minusthick portlet-toggle'>" + ui.item.find(".portlet-header") + "</span>");
                    // window.setTimeout(function(){window.location.reload()}, 4000);
                },
                error: function(response) {
                    console.log('Error!');
                    //handle.html("<span class='ui-icon ui-icon-minusthick portlet-toggle'>" + html + "</span>");
                }
            });
        }

Any help would be greatly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire