Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > สอบถามเรื่องการ Drag and Drop แถวของตารางสองตาราง พร้อมกับส่งค่ามาคำนวณครับ ตามรูป



 

สอบถามเรื่องการ Drag and Drop แถวของตารางสองตาราง พร้อมกับส่งค่ามาคำนวณครับ ตามรูป

 



Topic : 126841



โพสกระทู้ ( 318 )
บทความ ( 0 )



สถานะออฟไลน์




สอบถามเรื่องการ Drag and Drop แถวของตารางสองตาราง พร้อมกับส่งค่ามาคำนวณครับ ตามรูป

ตัวอย่างเช่น
มี Table 1 และ Table 2
Table 1 จะแบ่งเป็น Section ต่างๆ ต้องการนำแถวจาก Table 2 มาใส่แต่ละ section ของ Table 1 ตัวอย่างเช่น

แถวที่ 4 ของ Table 2 ใส่ใน Section 1 ของตารางที่ 1 พร้อมกับคำนวณ Value ใหม่
แถวที่ 5 ของ Table 2 ใส่ใน Section 2 ของตารางที่ 1 พร้อมกับคำนวณ Value ใหม่

ใครมีวิธีช่วยบอกผมทีครับ ทำมาสองวันแล้ว T-T

ภาพประกอบครับ
sortable



Tag : PHP, Ms SQL Server 2012, JavaScript, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2017-03-16 09:53:16 By : angelkiller9 View : 1070 Reply : 5
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Drag and Drop ยากนะครับ จะต้องหาพวก jQuery UI มาใช้ครับ ถ้าหาไม่มีก็เขียนเองยาก






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-03-16 10:28:57 By : mr.win
 


 

No. 2



โพสกระทู้ ( 318 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : mr.win เมื่อวันที่ 2017-03-16 10:28:57
รายละเอียดของการตอบ ::
ใช่ครับ ตอนนี้ผมลองใช้ jquery-ui มา แต่ลากวางไปมาได้ แต่ผมจะทำให้ ผล sum section มันคำนวณใหม่ ไม่ได้ ครับ

ตัวอย่างโค้ดนะครับ ผมลองลอกมาจากที่อื่น
Code (PHP)
<?php
require 'config/show-error.php';
?>
<!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">-->
    <title></title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="styles/css/bootstrap.min.css">
    <link rel="stylesheet" href="styles/font-awesome-4.6.3/css/font-awesome.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <link rel="stylesheet" href="styles/css/non-responsive.css" />

    <!-- jQuery-UI CSS -->
    <script src="styles/jquery-ui/jquery-ui.css"></script>

    <style type="text/css">
    ul li {
        min-width: 200px;
    }
    .dragging li.ui-state-hover {
        min-width: 240px;
    }
    .dragging .ui-state-hover a {
        color:green !important;
        font-weight: bold;
    }
    th,td {
        padding: 2px 4px;
        border: 1px solid;
    }
    .connectedSortable tr, .ui-sortable-helper {
        cursor: move;
    }
    .connectedSortable tr:first-child {
        /*cursor: default;*/
        cursor: move;
    }
    .ui-sortable-placeholder {
        background: yellow;
    }

    div.tableScroll {
      position: fixed;
    }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="row">
        <div class="col-xs-6">
          <table id="table1" class="table table-bordered table-condensed">
            <tbody>
              <tr>
                <td>
                  <table id="table-droppable1" class="table table-bordered table-condensed">
                    <thead>
                      <tr>
                        <th colspan="3" class="text-center">Section 1</th>
                      </tr>
                      <tr>
                        <th class="text-center">#</th>
                        <th class="text-center">Color</th>
                        <th class="text-center">Value</th>
                      </tr>
                    </thead>
                    <tbody class="connectedSortable">
                      <tr>
                        <td class="text-center">1.1</td>
                        <td class="text-center">Red</td>
                        <td class="text-center">3</td>
                      </tr>
                      <tr>
                        <td class="text-center">1.2</td>
                        <td class="text-center">White</td>
                        <td class="text-center">3</td>
                      </tr>
                      <tr>
                        <td class="text-center">1.3</td>
                        <td class="text-center">Blue</td>
                        <td class="text-center">3</td>
                      </tr>
                    </tbody>
                    <tfoot>
                      <tr id="sum1">
                        <td colspan="2" class="text-center">Sum Section 1</td>
                        <td class="text-center">9</td>
                      </tr>
                    </tfoot>
                  </table>
                  <table id="table-droppable2" class="table table-bordered table-condensed">
                    <thead>
                      <tr>
                        <th colspan="3" class="text-center">Section 2</th>
                      </tr>
                      <tr>
                        <th class="text-center">#</th>
                        <th class="text-center">Color</th>
                        <th class="text-center">Value</th>
                      </tr>
                    </thead>
                    <tbody class="connectedSortable">
                      <tr>
                        <td class="text-center">1.1</td>
                        <td class="text-center">White</td>
                        <td class="text-center">3</td>
                      </tr>
                      <tr>
                        <td class="text-center">1.2</td>
                        <td class="text-center">Red</td>
                        <td class="text-center">3</td>
                      </tr>
                    </tbody>
                    <tfoot>
                      <tr id="sum2">
                        <td colspan="2" class="text-center">Sum Section 2</td>
                        <td class="text-center">6</td>
                      </tr>
                    </tfoot>
                  </table>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="col-xs-6">
          <table id="table-draggable" class="table table-bordered table-condensed">
            <thead>
              <tr>
                <th class="text-center">#</th>
                <th class="text-center">Color</th>
                <th class="text-center">Value</th>
              </tr>
            </thead>
            <tbody class="connectedSortable">
              <tr>
                <td class="text-center">2.1</td>
                <td class="text-center">Green</td>
                <td class="text-center">1</td>
              </tr>
              <tr>
                <td class="text-center">2.2</td>
                <td class="text-center">Black</td>
                <td class="text-center">2</td>
              </tr>
              <tr>
                <td class="text-center">2.3</td>
                <td class="text-center">Orange</td>
                <td class="text-center">4</td>
              </tr>
              <tr>
                <td class="text-center">2.4</td>
                <td class="text-center">Yellow</td>
                <td class="text-center">5</td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="styles/js/jquery-3.1.1.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="styles/js/bootstrap.min.js"></script>
    <!-- jQuery-UI JS -->
    <script src="styles/jquery-ui/jquery-ui.min.js"></script>

    <script type="text/javascript">
    $(document).ready(function() {

      var $tabs = $('#table-draggable');

      $( "tbody.connectedSortable" ).sortable({
        connectWith: ".connectedSortable",
        appendTo: $tabs,
        helper: "clone",
        //revert: "invalid",
        zIndex: 99999,
        stop: function(event, ui){
          var drag_value = $(this).data().uiSortable.currentItem.closest('tr').find('td:eq(2)').text();
          var drop_value = $(this).data().uiSortable.currentItem.closest('#sum1').find('td:eq(1)').text();
          alert(drop_value);
          //alert(value);
          console.log(drop_value);
        }
      }).disableSelection();

      $( ".nav-tabs > li", $tabs ).droppable({
        accept: ".connectedSortable tr",
        hoverClass: "ui-state-hover",
        drop: function(event, ui) {
          return false;
        }
      });

    });
    </script>
  </body>
</html>



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-03-16 10:54:24 By : angelkiller9
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

เรื่องอ่านค่า sum แต่ล่ะ table ทำไม่ยากนะครับ แค่ใช้ jQuery Loop ตัว table แล้วก็ find หา id ที่ต้องการครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-03-16 11:07:02 By : mr.win
 


 

No. 4



โพสกระทู้ ( 318 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : mr.win เมื่อวันที่ 2017-03-16 11:07:02
รายละเอียดของการตอบ ::
นั่นแหละครับ ที่ผมไปต่อไม่เป็น ถ้าดูจาก javascript ที่เขียนไว้
var drag_value = $(this).data().uiSortable.currentItem.closest('tr').find('td:eq(2)').text(); จะได้ค่าของตารางที่ 2 มา
ทีนี้เราจะนำมารวมกับ sum section ผมเขียนไม่ถูก

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-03-16 11:13:36 By : angelkiller9
 


 

No. 5



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ประมาณนี้ครับ

Code (JavaScript)
	$("table#table_id input[id*='xxxx']").each(function (index) {
		var crtlInput1 = $("table#table_id input[id*='txtText1']").eq(index);
		var crtlInput2 = $("table#table_id input[id*='txtText2']").eq(index);

	}); 

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-03-16 15:05:13 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการ Drag and Drop แถวของตารางสองตาราง พร้อมกับส่งค่ามาคำนวณครับ ตามรูป
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่