这发生在Laravel 4.2和yajra / laravel-datatables-oracle":" ~3.0"
表已呈现并且已经是分页,但是顺序和过滤器不起作用。实际上,它总是返回相同的信息,就像未应用过滤器一样。还有什么必要通过考虑现有的连接来使一切工作吗?
我的控制器:
public function api() {
$params = Input::all();
$warehouse = $this->warehouse->getDefaultByTenant(current_tenant());
$items = $this->inventory->dataTables($warehouse, $params);
return $items;
}
我的存储库:
public function dataTables(Warehouse $warehouse, $params) {
$a = DB::table('inventories')
->join('variants', 'inventories.variant_id', '=', 'variants.id')
->join('tenant_variants', 'inventories.variant_id', '=', 'tenant_variants.id')
->join('products', 'variants.product_id', '=', 'products.id')
->join('variant_translations', 'variant_translations.variant_id', '=', 'variants.id', 'left outer')
->join('product_translations', 'product_translations.product_id', '=', 'products.id')
->where('inventories.warehouse_id', $warehouse->id)
->where('product_translations.locale', $warehouse->getTenantLocale())
->whereNull('variants.deleted_at')->orderBy('product_translations.name');
if (isset($params['search[value]']) && ($k = $params['search[value]'])) {
$query = $query
->where(function ($subquery) use ($k) {
return $subquery
->where('product_translations.name', 'like', "%%{$k}%%")
->orWhere('variants.sku', 'like', "%%{$k}%%")
->orWhere('variant_translations.name', 'like', "%%{$k}%%");
});
}
return Datatables::of($a)->addColumn('actions', 'action here')->make(true);
}
我的JS
$('.table-inventory').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {url: "route_to_api", dataSrc: "data"},
columns: [
{ data: 'sku' },
{ data: 'name' },
{ data: 'position' },
{ data: 'count_on_hand' },
{ data: 'count_on_hand' },
{ data: 'critical_stock_level' },
{ data: 'retail_price' },
{ data: 'wholesale_price' },
{ data: 'qty1_threshold' },
{ data: 'qty2_threshold' },
{ data: 'permalink_classico' },
{ data: 'ml_classico_price' },
{ data: 'id_ml_premium' },
{ data: 'ml_premium_price' },
]
} );
答案 0 :(得分:0)
我能够解决过滤器,我是手动完成的,但现在我需要解决这个问题。
if ($k = $params['search']['value']) {
$a = $a
->where(function ($subquery) use ($k) {
return $subquery
->where('product_translations.name', 'like', "%%{$k}%%")
->orWhere('variants.sku', 'like', "%%{$k}%%")
->orWhere('inventories.position', 'like', "%%{$k}%%")
->orWhere('variant_translations.name', 'like', "%%{$k}%%");
});
}