I have a table in database with 73k records. So I want to show it in only one table on view using Datatables.
This is table should be: Datatables in client side
I already have a table with datatables but It's limited item. The first column is not in database, "Show Image" column is special feature, when manager hover over this text, the image shown I want to use datatable in server side to load all data with changing the appearance. So I make a controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Yajra\Datatables\Datatables;
use App\Models\GS1;
class DataTablesController extends Controller
{
private $sa24Repository;
// function __construct(SA24Repository $sa24Repository)
// {
// $this->sa24Repository = $sa24Repository;
// }
public function getIndex() {;
return Datatables::of(Product::query())->make(true);
}
}
?>
with a simple view: Products table It work well but when I type in search input, It search all column. And I have to add this code to using filter:
<script>
$('.testTable').dataTable();
$.fn.dataTable.ext.errMode = 'throw';
$('.testTable').dataTable({
destroy: true,
processing: true,
serverSide: true,
ajax: '/datatables',
columns: [
{data: 'gtin'},
{data: 'brand_name'},
{data: 'description_short'}
]
});
</script>
If I remove this codes:
columns: [
{data: 'gtin'},
{data: 'brand_name'},
{data: 'description_short'}
]
When I search Browser logged:
Uncaught Error: DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
at Ae (all.js?v=1484881746:6)
at k (all.js?v=1484881746:5)
at j (all.js?v=1484881746:5)
at M (all.js?v=1484881746:5)
at U (all.js?v=1484881746:6)
at all.js?v=1484881746:5
at d (all.js?v=1484881746:5)
at Object.success (all.js?v=1484881746:5)
at d (all.js?v=1484881746:2)
at Object.fireWith [as resolveWith] (all.js?v=1484881746:2)
and I can't search anything
So could you help me to using datatable to search any columns I want to, and I don't have to add this snippet in script:
columns: [
{data: 'gtin'},
{data: 'brand_name'},
{data: 'description_short'}
]