How to create Dynamic Drag and Drop table rows using jQuery Ajax? Last Updated : 07 Aug, 2024 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss the method of How to create Dynamic and Drop table rows using JQuery Ajax. We will use jQuery and HTML CSS to perform the operations of Drag and Drop on the table row.First to perform the operations of the Drag and Drop table row we need two jQuery libraries without these libraries we can't perform the Drag and Drop operations on the table row. The required two libraries are:jQuery Ajax min.js: It will help us to perform the Drag and Drop operation on the table row:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>jQuery-UI: This as the name suggests, it's used for showing user interface operations:<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>Basically Drag and Drop operations on table rows means we can interchange the table row with each other by only operating Drag and Drop operations we need to only Drag and one row Drop it on another row with which we want to perform Drag and Drop operations it's basically used for change data and for the correctness of data when we write or add wrong data on a table.Approach: First we create table by using table and td , tr tag in our html code and we add one h1 tag for heading through which i explained what we are making and in first tag or tr we add three column first for id second, language and last one for preference and we add id 1 to 8 and in language we write some coding language and at last we are adding preference which we will set stable it means when we will perform Drag and Drop operations so that preference will not change their sequences its always static 1 to 8 only two column / row change id and preference according to perform operation by user and after writing code for table we add jQuery libraries without which we can't operate Drag and Drop operations and the we give id in table GFG and at last we write js first we create one function in which we will use GFG id and we will use sortable method and we use droponEmpty as a false default and after we start operation by using one more function and we addclass select and for stop the operation we will make one other function and set the stop function and write code for stop and successful showing interchange table operations on table row and we set GFG greater than 0 which and use findmethod in which we use td for Drag and Drop operations so with the help of these code we can perform Drag and Drop operations on table row.Example: This is the implementation of the above approach: HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dynamic Drag and Drop table rows using jQuery Ajax</title> <style> body { display: flex; flex-direction: column; align-items: center; } table th, table td { width: 50px; padding: 5px; border: 0.5px solid black; } .GFG { color: green; } .OK { font-size: 18px; } </style> <script type="text/javascript" src= "https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <link rel="stylesheet" href= "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css" /> <script type="text/javascript" src= "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"> </script> <script type="text/javascript" src= "https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"> </script> </head> <body> <h2 class="GFG">GeeksForGeeks</h2> <p class="OK">Drag and Drop table row</p> <div> <table id="GFG"> <tr> <td>ID</td> <th>Language</th> <th>Preference</th> </tr> <tr> <td>1</td> <td>Java</td> <td>1</td> </tr> <tr> <td>2</td> <td>C++</td> <td>2</td> </tr> <tr> <td>3</td> <td>Python</td> <td>3</td> </tr> <tr> <td>4</td> <td>HTML</td> <td>4</td> </tr> <tr> <td>5</td> <td>CSS</td> <td>5</td> </tr> <tr> <td>6</td> <td>Javascript</td> <td>6</td> </tr> <tr> <td>7</td> <td>MySql</td> <td>7</td> </tr> <tr> <td>8</td> <td>PHP</td> <td>8</td> </tr> </table> </div> <script> $(function () { $("#GFG").sortable({ items: 'tr:not(tr:first-child)', dropOnEmpty: false, start: function (G, ui) { ui.item.addClass("select"); }, stop: function (G, ui) { ui.item.removeClass("select"); $(this).find("tr").each(function (GFG) { if (GFG > 0) { $(this).find("td").eq(2).html(GFG); } }); } }); }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to create Dynamic Drag and Drop table rows using jQuery Ajax? prathamsahani0368 Follow Improve Article Tags : Technical Scripter Web Technologies JQuery Technical Scripter 2022 jQuery-AJAX jQuery-Questions +2 More Similar Reads How to Dynamically Add/Remove Table Rows using jQuery? We will dynamically add/remove rows from an HTML table using jQuery. jQuery provides us with a lot of methods to perform various tasks. To dynamically add and remove the rows from an HTML table, we are also going to use some of these jQuery methods like append(), remove(), etc.Adding a rowTo add a r 3 min read How to create a drag and drop feature for reordering the images using HTML CSS and jQueryUI ? In this article, we are given an images gallery and the task is to re-arrange the order of images in the list or grid by dragging and dropping. The jQuery UI framework provides a sortable() function that helps in re-ordering list items by using the mouse. With this functionality, the list items beco 3 min read How to Add Edit and Delete Table Row in jQuery ? In this article, we will create an example of how to add, edit and delete table rows in jQuery. For creating this functionality we need to know about the basics of the HTML table, jQuery basic functionality. Table row: An HTML table is a combination of rows and columns. The table row is in the horiz 3 min read How to add table row in a table using jQuery? In jQuery, adding a row to a table refers to dynamically inserting a new table row (<tr>) into an existing HTML table. This functionality allows developers to update and manage table content in real-time, enhancing interactivity and user experience without reloading the page.Steps to add table 2 min read How to fetch data from JSON file and display in HTML table using jQuery ? The task is to fetch data from the given JSON file and convert data into an HTML table. Approach: We have a JSON file containing data in the form of an array of objects. In our code, we are using jQuery to complete our task. The jQuery code uses getJSON() method to fetch the data from the file's loc 3 min read Create a Sortable and Filterable Table using JavaScript In this article, we will demonstrate how to create a sortable and filtrable table using JavaScript. This custom table will have the functionality of editing or removing individual items along with sorting and filtering items according to different fields. Also, a form is attached so that the user ca 6 min read How to load data from JavaScript array using jQuery DataTables plugin ? DataTables are a modern jQuery plugin for adding interactive and advanced controls to HTML tables for our webpages. It is a simple-to-use plug-in with a huge range of options for the developer's custom changes. The common features of the DataTable plugin are paging, multiple column ordering, sorting 2 min read How to handle events using jQuery DataTables plugin? DataTables are a modern jQuery plugin for adding interactive and advanced controls to HTML tables for our webpage. It is a simple-to-use jQuery plug-in with a huge range of many options for the developer's custom changes. The common features of DataTables are sorting, searching, pagination, and mult 3 min read jQuery UI Sortable create Event 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 appl 3 min read jQuery UI | draggable() and droppable() methods jQuery UI is a mixture of methods and a set of user interface effects, widgets, interactions and themes which can be provided in the web page using jQuery methods. If you want to build up a powerful web application that includes various features such as dragging, dropping, date picker, tooltips, etc 5 min read Like