Open In App

jQuery UI Sortable receive Event

Improve
Improve
Like Article
Like
Save
Share
Report

jQuery UI is a web-based technology and consists of various GUI widgets, visual effects, and themes. These features can be implemented using the jQuery JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add widgets easily.

The jQuery UI Sortable receive Event is used to trigger when an item from a connected sortable list has been dropped into another list.

Syntax:

  • We need to initialize the sortable widget with the receive callback function

    $( ".selector" ).sortable({
    receive: function( event, ui ) {}
    });
  •  

  • Bind an event listener to the sort receive event:

    $( ".selector" ).on( "sortreceive", function( event, ui ) {} );

Parameters: These are the following parameters that are accepted. 

  • event: This event is triggered when the sort receives an item.
  • ui: This parameter is of type object with below-given options.
    • helper: This parameter is the jQuery object representing the sorted helper.
    • item: This parameter is the jQuery object that represents the current dragged item.
    • offset: This parameter is the current absolute position of the helper object which is represented as { top, left }.
    • position: This parameter is the current position of the helper object which is represented as { top, left }.
    • originalPosition: This parameter is the original position of the helper object which is represented as { top, left }.
    • sender: This parameter is the sortable item of type jQuery object coming from moving from one sortable to another.
    • placeholder: This parameter is the element that is used as a placeholder. This is of type jQuery object.

CDN Link: Below are some jQuery Mobile scripts that will be needed for your project so add these to your project.

<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src= “https://code.jquery.com/jquery-1.12.4.js”></script>
<script src= “https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>

Example: This example describes the uses of the jQuery UI Sortable receive Event.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <link rel="stylesheet"
          href=
    <script 
          src=
    </script>
    <script 
          src=
    </script>
  
    <style>
        #sortable-1, #sortable-2 { 
            list-style-type: none; 
            width: 150px; 
            }
        #sortable-1 li, #sortable-2 li { 
            padding: 0.4em; 
            font-size: 17px; 
            height: 16px; 
            color: black;
            background-color: green;
        }
  
    </style>
  
    <script>
        $(function() {
            $( "#sortable-1" ).sortable({
                   receive : function (event, ui) {
                    $(".res").html ($(".res").html () 
                     + "<b>Receive</b><br>");
                   }
            });
            $( "#sortable-2" ).sortable({
                   connectWith : "#sortable-1, #sortable-2"
            });
        });
    </script>
  
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable receive Event</h4>
  
        <hr />
        <div class = "list_data">
            <div class = "list_data1"
                <h3>Name</h3>
                <ul id = "sortable-1">
                    <li class = "ui-state-default">GFG1</li>
                    <li class = "ui-state-default">GFG2</li>
                    <li class = "ui-state-default">GFG3</li>
                </ul>
            </div>
            <div class = "list_data1">
                <h3>Mark</h3
                <ul id = "sortable-2">
                    <li class = "ui-state-default">90</li>
                    <li class = "ui-state-default">80</li>
                    <li class = "ui-state-default">70</li>
                </ul>
            </div>
        </div>
          
        <hr />
        <div class="res"></div>
    </center>
</body>
  
</html>


Output:

Reference: https://api.jqueryui.com/sortable/#event-receive 



Last Updated : 10 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads