php - 如何使用可排序的 jquery UI 禁用表中的特定列?
问题描述
我有一个带有 jquery 可排序插件的表。您可以拖放项目,然后保存新订单。我的问题是,我如何禁用表格的列,以便我可以通过名称列拖放?
HTML 代码
<table class="table table-bordered" id="users" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Spotify</th>
<th>Instagram</th>
<th>Soundcloud</th>
<th>Facebook</th>
<th>Website</th>
<th>Options</th>
</tr>
</thead>
<tbody id="sortable">
@if(count($rows) > 0)
@foreach($rows as $value)
<tr id="{{ $value->id }}">
<td>{{ $value->name }}</td>
<td>
<img src="{{ $value->getImage('s') }}" >
</td>
<td>{{ $value->spotify_username }}</td>
<td>{{ $value->instagram_username }}</td>
<td>{{ $value->soundcloud_username }}</td>
<td>{{ $value->facebook_username }}</td>
<td>{{ $value->website_url }}</td>
<td class="text-center text-white">
<a data-placement="bottom" title='Additional info about {{ $value->name }}' href='{{ route("artists.view", ["artist" => $value->id]) }}' class="btn btn-sm btn-info tooltip-custom">{{ __('Info') }}</a>
<a data-placement="bottom" title='Edit {{ $value->name }}' href='{{ route("artists.edit", ["artist" => $value->id]) }}' class="btn btn-sm btn-primary tooltip-custom">{{ __('Edit') }}</a>
<a data-placement="bottom" title='Delete {{ $value->name }}' data-name='{{ $value->name }}' data-toggle="modal" data-target="#deleteModal" data-href='{{ route("artists.delete", ["artist" => $value->id]) }}' class="btn btn-sm btn-danger tooltip-custom">{{ __('Delete') }}</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
脚本代码
$( function() {
$( "#sortable" ).sortable({
update: function (event, ui){
$("#input-new-order-state").val($('#sortable').sortable("toArray"));
$("#form-state").removeClass('d-none');
}
});
$( "#sortable" ).disableSelection();
});
解决方案
如果有人需要这个,我解决了。我添加"handle": ".enable-drag",
到脚本中,并添加到class="enable-drag"
第一个td
. 现在您只能拖放第一列。
$( function() {
$( "#sortable" ).sortable({
"handle": ".enable-drag",
update: function (event, ui){
$("#input-new-order-state").val($('#sortable').sortable("toArray"));
$("#form-state").removeClass('d-none');
}
});
$( "#sortable" ).disableSelection();
} );
<div class="table-responsive">
<table class="table table-bordered" id="users" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Image</th>
<th>Spotify</th>
<th>Instagram</th>
<th>Soundcloud</th>
<th>Facebook</th>
<th>Website</th>
<th>Options</th>
</tr>
</thead>
<tbody id="sortable">
@if(count($rows) > 0)
@foreach($rows as $value)
<tr id="{{ $value->id }}">
<td class="enable-drag">{{ $value->name }}</td>
<td>
<img src="{{ $value->getImage('s') }}" >
</td>
<td>{{ $value->spotify_username }}</td>
<td>{{ $value->instagram_username }}</td>
<td>{{ $value->soundcloud_username }}</td>
<td>{{ $value->facebook_username }}</td>
<td>{{ $value->website_url }}</td>
<td class="text-center text-white">
<a data-placement="bottom" title='Additional info about {{ $value->name }}' href='{{ route("artists.view", ["artist" => $value->id]) }}' class="btn btn-sm btn-info tooltip-custom">{{ __('Info') }}</a>
<a data-placement="bottom" title='Edit {{ $value->name }}' href='{{ route("artists.edit", ["artist" => $value->id]) }}' class="btn btn-sm btn-primary tooltip-custom">{{ __('Edit') }}</a>
<a data-placement="bottom" title='Delete {{ $value->name }}' data-name='{{ $value->name }}' data-toggle="modal" data-target="#deleteModal" data-href='{{ route("artists.delete", ["artist" => $value->id]) }}' class="btn btn-sm btn-danger tooltip-custom">{{ __('Delete') }}</a>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
推荐阅读
- arm - 无法在 STM32H753 上写入 TMC/ETF 寄存器
- selenium-webdriver - 在 selenium -Java 中出现错误“过时的元素引用:元素未附加到页面文档”
- c# - 如何解决:“单声道版本不匹配”
- javascript - 如何使用 vuejs 指令或组件优雅地编写此代码?
- javascript - 具有对象数组和对象到对象的通用映射函数
- r - 如何在R中保存复杂列表的结构
- git - Travis-ci:.travis.yml 中每个分支的环境变量
- java - 为什么我的协程异步只能在 runBlocking 内工作?
- sql - VB.NET:数据列日期时间设置 NullValue
- java - 动态注入 Google Guice bean