0
布局:包含具有“展开”按钮的行的表格。展开按钮显示该行的所有子项,所有子项都与父行共享一些公用数据。HTML/JQuery对子表排序并使某些行不可用?
目标:在父母之间拖动孩子;即将某个子集的数据移动到另一个集合,并根据新父母的数据自动编辑某些字段。
到目前为止,我已经有了拓展亚行的桌子,但我无法围绕如何让孩子在父母之间拖动。我不想重新排列父行,它们应该是静态的。该表是动态创建的,数据从数据库中获取。
表:
<table id="loot-table" class="table table-striped">
<thead>
<tr>
<th>Min Level Required</th>
<th>Min Tokens Required</th>
<th>Type of Loot Dropped</th>
<th>Loot Group</th>
<th>Name of Loot Dropped</th>
<th>Quantity of Loot Dropped</th>
<th>Weight of Loot Dropped</th>
<th>Loot Is Available:</th>
</tr>
</thead>
<tbody>
<?php $loot_group_count=-1; foreach($event['lockbox_loot'] as $lockbox_loot){ $loot_group_count++; ?>
<tr class="loot-header-row">
<td><input type="number" value="<?php echo $lockbox_loot['min_level_required']; ?>"></td>
<td><input type="number" value="<?php echo $lockbox_loot['min_tokens_required']; ?>"></td>
<td><input name="loot_group_id[<?php echo $loot_group_count; ?>]" type="text" value="<?php echo $lockbox_loot['loot_group_id']; ?>"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><a href="#" class="loot-table-expand-btn" data-group-id="<?php echo $loot_group_count; ?>">Expand</a></td>
</tr>
<?php if($loot){ $i=-1; foreach($loot as $lootitem){
if($lockbox_loot['loot_group_id'] === $lootitem['loot_group_id']){ $i++; ?>
<tr class="loot-row-<?php echo $loot_group_count; ?> hide">
<td></td>
<td></td>
<td><input name="item_loot_group_id[<?php echo $loot_group_count; ?>][<?php echo $i; ?>]" type="text" value="<?php echo $lootitem['loot_group_id']; ?>" disabled="disabled"></td>
<td>
<select name="loot-type[<?php echo $i; ?>]">
<option value="money" <?php if($lootitem['loot_type']==="money"){echo "selected";}; ?>>Money</option>
<option value="respect" <?php if($lootitem['loot_type']==="respect"){echo "selected";}; ?>>Respect</option>
<option value="item" <?php if($lootitem['loot_type']==="item"){echo "selected";}; ?>>Item</option>
<option value="mafia" <?php if($lootitem['loot_type']==="mafia"){echo "selected";}; ?>>Mafia</option>
</select>
</td>
<td><input name="loot_id[<?php echo $i; ?>]" type="text" value="<?php echo $lootitem['loot_id']; ?>"></td>
<td><input name="quantity[<?php echo $i; ?>]" type="number" min="0" value="<?php echo $lootitem['quantity']; ?>"></td>
<td><input name="loot_weight[<?php echo $i; ?>]" type="number" min="0" value="<?php echo $lootitem['loot_weight']; ?>"></td>
<td><input name="is_available[<?php echo $i; ?>]" type="checkbox" value="<?php echo $lootitem['is_available']; ?>" <?php if($lootitem['is_available']){echo "checked";}; ?>></td>
</tr>
<?php }}}} ?>
</tbody>
</table>
jQuery代码为扩大隐藏的单元格:
$(".loot-table-expand-btn").each(function() {
$(this).on('click', function(){
var group_id = $(this).attr('data-group-id');
$('.loot-row-' + group_id).each(function(){
if($(this).is(":visible")) {
hidden = true;
$(this).hide();
} else {
hidden = false;
$(this).show();
}
});
if(hidden) {
$(this).html('Expand');
} else {
$(this).html('Collapse');
}
return false;
});
});