CodeIgniter 4 DataTables Advanced Usage

    $db = db_connect();
    $builder = $db->table('customers')->select('customerNumber, customerName, phone, city, country, postalCode,create_date')->where('create_date',date('Y'));

    return DataTable::of($builder)
    ->filter(function ($builder, $request) {
        
        if ($request->country)
            $builder->where('country', $request->country);

    })
    ->postQuery(function($builder){

       $builder->groupStart()
          ->where('customerNumber IS NULL')
          ->orWhere('YEAR(create_date)', '2024')
                            ->groupEnd();

    })
    ->toJson();
Scroll to Top