Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterColumn wrong behavior? #108

Open
diorgesl opened this issue May 10, 2024 · 1 comment
Open

filterColumn wrong behavior? #108

diorgesl opened this issue May 10, 2024 · 1 comment

Comments

@diorgesl
Copy link

Look this code

public function plex_cliente_datatables() {
        $clientes = PlexCliente::query();
        return DataTables::eloquent($clientes->with('servicos_alias'))
            ->addColumn('servicos_alias', function(PlexCliente $c) {
                $servicos = null;
                foreach($c->servicos_alias as $servico) {
                    $servicos .= $servico->id . ($servico->alias ? '(' . $servico->alias . ')' : ''). ', ';
                }
                return substr($servicos, 0, -2);
            })
            ->filterColumn('cpf_cnpj', function($query, $keyword) {
                $sql = "REPLACE(REPLACE(REPLACE(cpf_cnpj, '.', ''), '-', ''), '/', '')  LIKE ?";
                $keyword = preg_replace('/\D/', '', $keyword);
                $query->whereRaw($sql, ["%{$keyword}%"]);
            })
            ->toJson();
    }

When I use the filterColumn, the search works only for this column.

Can you help how to fix this?

@yajra
Copy link
Owner

yajra commented May 11, 2024

That is the expected behavior, filterColmn is only applied to the selected column.

Or do you mean, the search is not working at all except on cpf_cnpj? You can debug the SQL generated by setting APP_DEBUG=true and inspect the ajax request. Json response will display the SQL used by the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants