【发布时间】:2016-04-12 05:26:32
【问题描述】:
我需要帮助。
我正在使用 yajra/laravel-datatables 将数据表包含到我的项目中。
一切正常。
现在我想使用行重新排序扩展:https://datatables.net/extensions/rowreorder/
但是当我用一行进行拖放时似乎可以工作,但不工作。
我认为可能会重新加载,因为我使用 ajax url 加载数据,取消了我所做的重新排序。有可能吗?
嗯,这些是我的代码:
控制器:
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$med = new Medicinas;
return view('admin.medicinas.index', ['med' => $med->get()]);
}
/**
* Process datatables ajax request.
*
* @return \Illuminate\Http\JsonResponse
*/
public function anyData()
{
return Datatables::of(User::select('*'))->make(true);
}
路线:
Route::get('administrator/medicinas', [
'as' => 'admin.medicinas',
'uses' => 'MedicinasController@index'
]);
Route::controller('administrator/medicinas', 'MedicinasController', [
'anyData' => 'datatables.data',
'index' => 'administrator/medicinas',
]);
查看:
@extends('app')
@section('content')
<div class="col-xs-12 col-sm-10">
@foreach($med as $medicina)
<div class="col-xs-12 col-sm-4">
<a href="{{ route('medicina.edit', $medicina->id) }}" title="">{{ $medicina->nombre_comercial }}</a>
</div>
@endforeach
</div>
<table id="users-table" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Created At</th>
<th>Updated At</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Created At</th>
<th>Updated At</th>
</tr>
</tfoot>
</table>
<input type="text" name="" value="" placeholder="">
@endsection
@section('scripts')
<script type="text/javascript">
$(function() {
var table_id = '#' + 'users-table';
window.table = $(table_id).DataTable({
rowReorder: true,
processing: true,
serverSide: true,
ajax: '{!! route('datatables.data') !!}',
columns: [
{ data: 'id', name: 'id' },
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'created_at', name: 'created_at' },
{ data: 'updated_at', name: 'updated_at' }
]
});
window.table_h = $(table_id + ' thead th');
window.table_f = $(table_id + ' tfoot th');
});
</script>
@endsection
【问题讨论】:
-
您是否包括重新排序文件? (js+css)
-
我唯一做过的js代码是在视图的末尾。在文档上,除了写“rowReorder:true”之外,我没有读过任何东西。如果还需要,请解释一下好吗?