omines / datatables捆绑包不会搜索datetime列

时间:2019-02-01 21:44:46

标签: symfony datatables

im使用捆绑包渲染数据表网格,该捆绑包称为omines / datatables-bundle。搜索对所有字段正确执行,除了fillAt列(即DateTimeColumn之一)之外,该类型由Omines专家定义。 这是我的操作代码:

public function index(Request $request, CarRepository $carRepository, DataTableFactory $dataTableFactory)
    {
        $table = $dataTableFactory->create()
            ->add('id', NumberColumn::class, ["orderable" => true, "searchable" => true])
            ->add('carBrand', TextColumn::class, ["field" => "brand.name", "orderable" => true, "label" => "Marca del Carro", "searchable" => true])
            ->add('model', TextColumn::class, ["field" => "car.model", "orderable" => true, "label" => "Modelo del Carro", "searchable" => true])
            ->add("filledAt", DateTimeColumn::class, ["format" => "Y-m-d H:i:s", "searchable" => true, "orderable" => true])
            ->add("fuelFilled", NumberColumn::class, ["render" => "%s L", "searchable" => true])
            ->add("price", NumberColumn::class, ["render" => "%s cuc", "searchable" => true])
            ->add("formerRead", NumberColumn::class, ["searchable" => true])
            ->add("currentRead", NumberColumn::class, ["searchable" => true])
            ->add("mileage", NumberColumn::class, ["searchable" => true])
            ->add('actions', TwigColumn::class, [
                'className' => 'buttons',
                'template' => 'frontend/supervisor/carfill/table-buttons.html.twig',
            ])
            ->addOrderBy('filledAt', DataTable::SORT_DESCENDING)
            ->createAdapter(ORMAdapter::class, [
                "entity" => CarFuelFillRecord::class,
                "query" => function(QueryBuilder $builder){
                    $builder
                        ->from("App:CarFuelFillRecord", "cffr")
                        ->select("cffr, car, brand")
                        ->leftJoin("cffr.car", "car")
                        ->leftJoin("car.brand", "brand")
                    ;
                }
            ])
            ->handleRequest($request);

        if ($table->isCallback()) {
            return $table->getResponse();
        }

        return $this->render('frontend/supervisor/carfill/index.html.twig', [
            'datatable' => $table,
            "cars" => $carRepository->findAll()
        ]);
    }

这是我模板的代码

<script>
$(function() { $('#carFuelFillRecords').initDataTables({{ datatable_settings(datatable) }},{searching: true}); });
</script>

我在做什么错?提前谢谢

1 个答案:

答案 0 :(得分:0)

认为这是由于您的日期格式和日期存储在数据库中的格式之间的差异。捆绑软件似乎完全在搜索输入的字符串,在您的情况下,其格式可能是“ Y-m-d H:i:s”,但在数据库中不是。因此找不到您输入的日期。