搜索和排序不起作用 - 数据表和 Laravel 4.2
Search and sort does not work - Datatables and Laravel 4.2
这发生在 Laravel 4.2 和 yajra / laravel-datatables-oracle ":" ~ 3.0 "
table 已呈现并且已经分页,但是,顺序和过滤器不起作用。事实上,它总是 returns 相同的信息,就好像没有应用过滤器一样。考虑现有的连接,是否还有其他必要的东西可以使一切正常工作?
我的控制器:
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' },
]
} );
我能够解决过滤器问题,我是手动解决的,但现在我需要解决排序问题。
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}%%");
});
}
这发生在 Laravel 4.2 和 yajra / laravel-datatables-oracle ":" ~ 3.0 "
table 已呈现并且已经分页,但是,顺序和过滤器不起作用。事实上,它总是 returns 相同的信息,就好像没有应用过滤器一样。考虑现有的连接,是否还有其他必要的东西可以使一切正常工作?
我的控制器:
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' },
]
} );
我能够解决过滤器问题,我是手动解决的,但现在我需要解决排序问题。
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}%%");
});
}