0

这发生在 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' },
        ]
    } );
4

1 回答 1

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}%%");
        });
    }
于 2017-09-08T03:52:15.637 回答