 |
|
ตัวอย่างครับ

form.php
Code (PHP)
<form method="post" id="form_dep_select" name="form_dep_select" onSubmit="JavaScript:return fncSubmit();" >
<script type="text/javascript">
var redipsURL = '/javascript/drag-and-drop-table-row/';
</script>
<!-- tables inside this DIV could contain drag-able content -->
<div id="redips-drag">
<!-- left container -->
<div id="left">
<table class="tbl0">
<colgroup>
<col width="100"/>
</colgroup>
<thead>
<tr>
<th class="redips-mark">กลุ่มA</th>
</tr>
</thead>
</table>
<div style="margin:0px; width:178px; height:318px; overflow: auto;">
<table class="tbl0">
<tbody>
<?php
foreach ($transportAll_branch_set_999 as $key => $value) {
?>
<tr class="rl">
<td class="redips-rowhandler"><div class="redips-drag redips-row"><?php echo $value->brAbbName; ?></div>
<input type="hidden" name="unit_select_dep_999" id="unit_select_dep_999" value="<?php echo $value->brParent_unit; ?>">
<input type="hidden" name="brAbbName_select_dep_999" id="brAbbName_select_dep_999" value="<?php echo $value->brAbbName; ?>">
</td>
</tr>
<?php } ?>
<tr>
<td class="redips-mark"><span>Message line</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- middle container -->
<div id="middle">
<table class="tbl1">
<colgroup>
<col width="100"/>
</colgroup>
<thead>
<tr>
<th class="redips-mark">กลุ่มB</th>
</tr>
</thead>
</table>
<div style="margin:0px; width:178px; height:318px; overflow: auto;">
<table class="tbl1">
<tbody>
<?php
foreach ($transportAll_branch_set_1 as $key => $value) {
?>
<tr class="rl">
<td class="redips-rowhandler"><div class="redips-drag redips-row"><?php echo $value->brAbbName; ?></div>
<input type="hidden" name="unit_select_dep_1" id="unit_select_dep_1" value="<?php echo $value->brParent_unit; ?>">
<input type="hidden" name="brAbbName_select_dep_1" id="brAbbName_select_dep_1" value="<?php echo $value->brAbbName; ?>">
</td>
</tr>
<?php } ?>
<tr>
<td class="redips-mark"><span>Message line</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- middle container -->
<div id="middle">
<table class="tbl2">
<colgroup>
<col width="100"/>
</colgroup>
<thead>
<tr>
<th class="redips-mark">กลุ่มC</th>
</tr>
</thead>
</table>
<div style="margin:0px; width:178px; height:318px; overflow: auto;">
<table class="tbl2">
<tbody>
<?php
foreach ($transportAll_branch_set_2 as $key => $value) {
?>
<tr class="rl">
<td class="redips-rowhandler"><div class="redips-drag redips-row"><?php echo $value->brAbbName; ?></div>
<input type="hidden" name="unit_select_dep_2" id="unit_select_dep_2" value="<?php echo $value->brParent_unit; ?>">
<input type="hidden" name="brAbbName_select_dep_2" id="brAbbName_select_dep_2" value="<?php echo $value->brAbbName; ?>">
</td>
</tr>
<?php } ?>
<tr>
<td class="redips-mark"><span>Message line</span></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- middle container -->
<div id="middle">
<table class="tbl3">
<colgroup>
<col width="100"/>
</colgroup>
<thead>
<tr>
<th class="redips-mark">กลุ่มD</th>
</tr>
</thead>
</table>
<div style="margin:0px; width:178px; height:318px; overflow: auto;">
<table class="tbl3">
<tbody>
<?php
foreach ($transportAll_branch_set_3 as $key => $value) {
?>
<tr class="rl">
<td class="redips-rowhandler"><div class="redips-drag redips-row"><?php echo $value->brAbbName; ?></div>
<input type="hidden" name="unit_select_dep_3" id="unit_select_dep_3" value="<?php echo $value->brParent_unit; ?>">
<input type="hidden" name="brAbbName_select_dep_3" id="brAbbName_select_dep_3" value="<?php echo $value->brAbbName; ?>">
</td>
</tr>
<?php } ?>
<tr>
<td class="redips-mark"><span>Message line</span></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="box-footer text-center">
<input type="submit" name="from_update_dep_select" id="from_update_dep_select" class="btn btn-primary btn-sm" style="width:75px;height:35px" value="บันทึก" />
<input type="button" class="btn btn-primary btn-sm" style="width:75px;height:35px" value="ล้างข้อมูล" onClick="javascript: window.location.reload()">
</div>
</form>
update.php
Code (PHP)
public function update_from_dep_select()
{
$code_select_dep_999=$this->input->post('unit_select_dep_999');
$br_abbName_select_dep_999=$this->input->post('brAbbName_select_dep_999');
$code_select_dep_1=$this->input->post('unit_select_dep_1');
$br_abbName_select_dep_1=$this->input->post('brAbbName_select_dep_1');
$code_select_dep_2=$this->input->post('unit_select_dep_2');
$br_abbName_select_dep_2=$this->input->post('brAbbName_select_dep_2');
$code_select_dep_3=$this->input->post('unit_select_dep_3');
$br_abbName_select_dep_3=$this->input->post('brAbbName_select_dep_3');
$code_select_dep_4=$this->input->post('unit_select_dep_4');
$br_abbName_select_dep_4=$this->input->post('brAbbName_select_dep_4');
//////////////////////// dep_select_999 dep_select_999 ////////////////////////////////
//////////////////////// dep_select_999 dep_select_999 ////////////////////////////////
if($code_select_dep_999 == 999){
$sql_dep_select_999 = "SELECT * FROM `branch` WHERE `brAbbName` = '$br_abbName_select_dep_999'";
$query_dep_select_999 = $this->db->query("$sql_dep_select_999");
$result_dep_select_999=$query_dep_select_999->result_array();
foreach ($result_dep_select_999 as $row_dep_select_999){
$br_code=$row_dep_select_999["brCode"];
}
$this->db->set('brParent_unit', 999);
$this->db->where('brCode', $br_code);
$this->db->update("branch");
}
//////////////////////// dep_select_1 dep_select_1 ////////////////////////////////
//////////////////////// dep_select_1 dep_select_1 ////////////////////////////////
if($code_select_dep_1 == 1){
$sql_dep_select_1 = "SELECT * FROM `branch` WHERE `brAbbName` = '$br_abbName_select_dep_1'";
$query_dep_select_1 = $this->db->query("$sql_dep_select_1");
$result_dep_select_1=$query_dep_select_1->result_array();
foreach ($result_dep_select_1 as $row_dep_select_1){
$br_code=$row_dep_select_1["brCode"];
}
$this->db->set('brParent_unit', 1);
$this->db->where('brCode', $br_code);
$this->db->update('branch');
}
//////////////////////// dep_select_2 dep_select_2 ////////////////////////////////
//////////////////////// dep_select_2 dep_select_2 ////////////////////////////////
if($code_select_dep_2 == 2){
$sql_dep_select_2 = "SELECT * FROM `branch` WHERE `brAbbName` = '$br_abbName_select_dep_2'";
$query_dep_select_2 = $this->db->query("$sql_dep_select_2");
$result_dep_select_2=$query_dep_select_2->result_array();
foreach ($result_dep_select_2 as $row_dep_select_2){
$br_code=$row_dep_select_2["brCode"];
}
$this->db->set('brParent_unit', 2);
$this->db->where('brCode', $br_code);
$this->db->update('branch');
}
//////////////////////// dep_select_3 dep_select_3 ////////////////////////////////
//////////////////////// dep_select_3 dep_select_3 ////////////////////////////////
if($code_select_dep_3 == 3){
$sql_dep_select_3 = "SELECT * FROM `branch` WHERE `brAbbName` = '$br_abbName_select_dep_3'";
$query_dep_select_3 = $this->db->query("$sql_dep_select_3");
$result_dep_select_3=$query_dep_select_3->result_array();
foreach ($result_dep_select_3 as $row_dep_select_3){
$br_code=$row_dep_select_3["brCode"];
}
$this->db->set('brParent_unit', 3);
$this->db->where('brCode', $br_code);
$this->db->update('branch');
}
//////////////////////// dep_select_4 dep_select_4 ////////////////////////////////
//////////////////////// dep_select_4 dep_select_4 ////////////////////////////////
if($code_select_dep_4 == 4){
$sql_dep_select_4 = "SELECT * FROM `branch` WHERE `brAbbName` = '$br_abbName_select_dep_4'";
$query_dep_select_4 = $this->db->query("$sql_dep_select_4");
$result_dep_select_4=$query_dep_select_4->result_array();
foreach ($result_dep_select_4 as $row_dep_select_4){
$br_code=$row_dep_select_4["brCode"];
}
$this->db->set('brParent_unit', 4);
$this->db->where('brCode', $br_code);
$this->db->update('branch');
}
redirect("backend/from_select_dep","refresh");
exit();
}
script.js
Code (JavaScript)
/*jslint white: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: false, bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxerr: 14 */
/*global window: false, REDIPS: true */
/* enable strict mode */
"use strict";
// define redipsInit variable
var redipsInit;
// redips initialization
redipsInit = function () {
// reference to the REDIPS.drag library and message line
var rd = REDIPS.drag,
msg;
// initialization
rd.init();
// set hover color for TD and TR
rd.hover.colorTd = '#FFCFAE';
rd.hover.colorTr = '#9BB3DA';
// set hover border for current TD and TR
rd.hover.borderTd = '2px solid #32568E';
rd.hover.borderTr = '2px solid #32568E';
// drop row after highlighted row (if row is dropped to other tables)
rd.rowDropMode = 'after';
// row was clicked - event handler
rd.event.rowClicked = function () {
// set current element (this is clicked TR)
var el = rd.obj;
// find parent table
el = rd.findParent('TABLE', el);
// every table has only one SPAN element to display messages
msg = el.getElementsByTagName('span')[0];
// display message
msg.innerHTML = 'Clicked';
};
// row was moved - event handler
rd.event.rowMoved = function () {
// set opacity for moved row
// rd.obj is reference of cloned row (mini table)
rd.rowOpacity(rd.obj, 85);
// set opacity for source row and change source row background color
// rd.objOld is reference of source row
rd.rowOpacity(rd.objOld, 20, 'White');
// display message
msg.innerHTML = 'Moved';
};
// row was not moved - event handler
rd.event.rowNotMoved = function () {
msg.innerHTML = 'Not moved';
};
// row was dropped - event handler
rd.event.rowDropped = function () {
// display message
msg.innerHTML = 'Dropped';
};
// row was dropped to the source - event handler
// mini table (cloned row) will be removed and source row should return to original state
rd.event.rowDroppedSource = function () {
// make source row completely visible (no opacity)
rd.rowOpacity(rd.objOld, 100);
// display message
msg.innerHTML = 'Dropped to the source';
};
/*
// how to cancel row drop to the table
rd.event.rowDroppedBefore = function () {
//
// JS logic
//
// return source row to its original state
rd.rowOpacity(rd.objOld, 100);
// cancel row drop
return false;
}
*/
// row position was changed - event handler
rd.event.rowChanged = function () {
// get target and source position (method returns positions as array)
var pos = rd.getPosition();
// display current table and current row
msg.innerHTML = 'Changed: ' + pos[0] + ' ' + pos[1];
};
};
// add onload event listener
if (window.addEventListener) {
window.addEventListener('load', redipsInit, false);
}
else if (window.attachEvent) {
window.attachEvent('onload', redipsInit);
}
คำถาม
1. อยากทราบว่าเมื่อเราจัดย้ายกลุ่มเสร็จแล้ว เมื่อกดบันทึก จะให้ update ข้อมูลเป็นของแต่ละกลุ่ม ครับ
เช่น
ข้อมูลที่อยู่ กลุ่มA ให้ update unit เป็น 1
ข้อมูลที่อยู่ กลุ่มB ให้ update unit เป็น 2
ข้อมูลที่อยู่ กลุ่มC ให้ update unit เป็น 3
ข้อมูลที่อยู่ กลุ่มD ให้ update unit เป็น 4
ประมาณนี้ครับ
2. หรืออีกวิธี ช่วยแนะนำ code แบบว่า พอลากข้อมูลไปกลุ่มไหน ก็ให้ update unit เป็นของกลุ่มนั้นไปเลย ต้องทำยังไงครับ
Tag : PHP, MySQL, JavaScript, MVC, CodeIgniter
|
ประวัติการแก้ไข 2017-10-16 11:26:43 2017-10-16 11:26:59 2017-10-16 19:53:46
|
 |
 |
 |
 |
Date :
2017-10-16 11:23:08 |
By :
StyleIndy |
View :
1101 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |