Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RowReorder DataTable : Static (Using foreach loop Data)
- Ref = https://www.itsolutionstuff.com/post/php-dynamic-drag-and-drop-table-rows-using-jquery-ajaxexample.html
- ----------------------------------------------------------
- 1. Add Library
- - jquery-ui.min.js
- OR
- - <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
- 2. <tbody class="row_position">
- 3. <tr id="<?php echo $user['id'] ?>">
- 4. Add Script
- <script type="text/javascript">
- $( ".row_position" ).sortable({
- delay: 150,
- stop: function() {
- var selectedData = new Array();
- $('.row_position>tr').each(function() {
- selectedData.push($(this).attr("id"));
- });
- updateOrder(selectedData);
- }
- });
- function updateOrder(data) {
- $.ajax({
- url:"url.php",
- type:'post',
- data:{position:data},
- success:function(){
- alert('your change successfully saved');
- }
- })
- }
- </script>
- 5. URL.php
- $position = $_POST['position'];
- $i=1;
- foreach($position as $k=>$v){
- $sql = "UPDATE tbl_name SET in_order=".$i." WHERE id=".$v;
- $mysqli->query($sql);
- $i++;
- }
- --------------------------------------------------------------------------
- help : "in_order" is table column name in table.
Add Comment
Please, Sign In to add comment