与columnFilter.js的数据表问题

时间:2015-09-08 09:53:52

标签: javascript jquery laravel datatable datatables

我在列过滤或分页后有数据服务器端的问题。首先,重新加载页面后 - 一切正常,数据正确。但在那之后我排序或过滤列,请求url返回错误。

这是我的jquery:

var customer_id = $('input[name=customer-id]').val();

// Data tables
$('#customers-list-data').DataTable({
    processing: true,
    serverSide: true,
    ajax: '/customers/edit/'+customer_id,
    columns: [
        { data: 'first_name', name: 'first_name' },
        { data: 'last_name', name: 'last_name' },
        { data: 'phone', name: 'phone' },
        { data: 'country', name: 'country' },
        { data: 'city', name: 'city' },
        { data: 'address', name: 'address' },
        { data: 'email', name: 'email' },
        { data: 'action', name: 'action', orderable: false, searchable: false}
    ],
pagingType: 'full_numbers',
    dom: '<"dt-top-row"Bfl>r<"dt-wrapper"t><"dt-row dt-bottom-row"<"row"<"col-sm-6"i><"col-sm-6 text-right"p>>>',
    buttons: [
        {
            extend: 'collection',
            text: 'Save <span class="caret" />',
            buttons : ['csvFlash', 'excelFlash', 'pdfFlash']
        },
        'colvis'
    ]
});

$('#customers-list-data').dataTable().columnFilter({
    sPlaceHolder: "head:after",
    aoColumns: [
        { type: "text" },
        { type: "text" },
        { type: "text" },
        { type: "text" },
        { type: "text" },
        { type: "text" },
        { type: "text" },
        null
    ]
});

这是laravel项目的方法:

public function getEdit(Request $request, Customer $customer)
{   
    if($request->ajax()) {

        $customer_data = $customer->Data()->get();

        return Datatables::of($customer_data)
                ->addColumn('action', function ($customer_data) {
                    return '<div class="btn-group">
                                <a href="#" class="btn btn-default"><i class="fa fa-edit"></i></a>
                                <a href="'.url('customers/delete_one/'.$customer_data->id.'/'.$customer_data->customers_id).'" class="btn btn-default"><i class="fa fa-times"></i></a>
                            </div>';
                })
                ->make(true);
    }
}

第一次请求网址:

http://address.com/customers/edit/39?draw=1&columns%5B0%5D%5Bdata%5D=first_name&columns%5B0%5D%5Bname%5D=first_name ...

过滤或排序后,分页:

http://address.com/customers/edit/39?draw=2&columns=%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D%2C%5Bobject+Object%5D&order=%5Bobject+Object%5D&start=10&length=10&search=%5Bobject+Object%5D&sRangeSeparator=~

Laravel调试错误:

in Request.php line 78
    at HandleExceptions->handleError('2', 'Illegal string offset 'column'', '/var/www/dev/vendor/yajra/laravel-datatables-oracle/src/yajra/Datatables/Request.php', '78', array('orderable' => array(), 'i' => '0', 'c' => '1')) in Request.php line 78

这是我的表:

&#13;
&#13;
<table id="customers-list-data" class="table table-striped table-bordered table-hover customers-table-list">
  <thead>
    <tr class="second">
      <th>First Name</th>
      <th>Last Name</th>
      <th>Phone</th>
      <th>Country</th>
      <th>City</th>
      <th>Address</th>
      <th>Email</th>
      <th>&nbsp;</th>
    </tr>
    <tr>
      <th style="width: 11%;">First Name</th>
      <th style="width: 11%;">Last Name</th>
      <th style="width: 11%;">Phone</th>
      <th style="width: 11%;">Country</th>
      <th style="width: 11%;">City</th>
      <th style="width: 11%;">Address</th>
      <th style="width: 11%;">Email</th>
      <th class="no-sort" style="width: 13%;">Actions</th>
    </tr>
  </thead>
</table>
&#13;
&#13;
&#13;

我使用的是库:

Laravel

http://datatables.yajrabox.com/

JS

 http://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js
 http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js

我认为这是这些版本的错误,因为旧数据库版本很好。

0 个答案:

没有答案