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 not triggering at version 9.2.0 #2091

Closed
mgcostaParedes opened this issue May 20, 2019 · 8 comments · Fixed by #2102
Closed

filterColumn not triggering at version 9.2.0 #2091

mgcostaParedes opened this issue May 20, 2019 · 8 comments · Fixed by #2102

Comments

@mgcostaParedes
Copy link

mgcostaParedes commented May 20, 2019

Summary of problem or feature request

Hello, after upgrading your awesome package to the version 9.2.0 , some of my filterColumns methods stopped working, I think the problem is related when i initialize the column with addColumn, then i assume the filterColumn doesnt work in version 9.2.0 at that column. When i downgrade to the version 9.1.1, the filters start to working again

Code snippet of problem

  $year = $request->input('year');
            //INIT QUERY
  $documentos = cabecalho_doc::with(['tipo_documento', 'creator', 'entidade', 'pessoa'])->leftJoin('doc_linhas', function($join) {
                    $join->on('doc_linhas.cabecalho_doc_id', '=', 'cabecalho_doc.id');
                    $join->on('doc_linhas.version', '=', 'cabecalho_doc.default_version');
   })->select('cabecalho_doc.id', 'data_doc', 'user_id', 'id_tipo_documento', 'serie_id', 'index_doc', 'nome_terceiro', 'id_terceiro', 'id_terceiro_unico', 'id_moeda', 'id_oportunidade', 'id_task', 'cabecalho_doc.desconto', 'cabecalho_doc.tipo_desconto', 'default_version', 'cabecalho_doc.updated_at', DB::raw('SUM(doc_linhas.preco_unit * doc_linhas.quantidade) as total'))->where('rascunho', 0)->whereNull('id_anulado')->groupBy('cabecalho_doc.id');

 if($year != 'all') { //GET BASED ON YEAR OF DROPDOWN
     $documentos->whereYear('data_doc', $year);
 }

 if(!Auth::user()->hasPermissionTo('Ver documentos de toda a empresa')) {
     $docs_shared = doc_shared::where('user_id', Auth::user()->id)->get(['cabecalho_doc_id']);
     $documentos->where(function($query) use ($docs_shared) {
          $query->where('user_id', Auth::user()->id)->orWhereIn('cabecalho_doc.id', $docs_shared);
     });
}

if(Auth::user()->hasPermissionTo('Apagar documento')) {
    $canDelete = true;
} else {
    $canDelete = false;
}

 //RETURN COLLECTION OF DATATABLES
            return Datatables::of($documentos)
              ->setRowId(function($data) {
                  return "rowDone_" . $data->id;
              })
              ->addColumn('#', function($data) {
                  return $data->present()->openTerceiro() . $data->present()->profilePic('32', '12', 'cliente-profile');
              })
              ->addColumn('criador', function($data) {
                  return ($data->creator) ? $data->creator->name : '---';
              })
              ->addColumn('ref', function($data) {
                  return $data->present()->text_table_ref;
              })
              ->editColumn('nome_terceiro', function($data) {
                  return  $data->present()->openTerceiro() . $data->nome_terceiro . "</a>";
              })
              ->editColumn('desconto', function($data) {
                  return number_format($data->desconto, 2) . ' ' . $data->present()->add_discount_sub();
              })
              ->editColumn('total', function($data) {
                  return number_format($data->total ?: 0, 2, ',', '');
              })
              ->addColumn('versoes', function($data) {
                  return $data->present()->constructVersions();
              })
              ->addColumn('opcoes', function($data) use($canDelete) {
                  return $data->present()->constructActionsTable($canDelete);
              })
              ->filterColumn('criador', function($query, $keyword) {
                  $query->where('user_id', $keyword);
              })
              ->filterColumn('ref', function($query, $keyword) {
                  $relations = oportunidade::where('nome_negocio', 'like', '%' . $keyword . '%')->get(['id']);
                  $query->whereIn('id_oportunidade', $relations);
              })
              ->removeColumn('total_doc')
              ->rawColumns(['#', 'opcoes', 'nome_terceiro', 'versoes', 'ref'])
              ->make(true);

System details

  • Windows 10
  • PHP VERSION - 7.1.3
  • Laravel Version - 5.8.0
  • Laravel-Datatables Version - 9.2.0
@yajra
Copy link
Owner

yajra commented May 21, 2019

Thanks for reporting, the only PR I know that have something to do with search is #2079. Will try to check this as soon as I can. Ping @apreiml, would you be able to confirm this? Thanks!

@artemsky
Copy link

Same thing

@yajra
Copy link
Owner

yajra commented May 25, 2019

Guys, would you be able to confirm if reverting #2079 would fix this issue? Will revert the PR if it's the culprit. Thanks!

@artemsky
Copy link

Guys, would you be able to confirm if reverting #2079 would fix this issue? Will revert the PR if it's the culprit. Thanks!

Yes, I confirm.
I think that the reason is that #2079 is blacklisting all columns that are added via addColumn

@apreiml
Copy link
Contributor

apreiml commented May 28, 2019

Wouldn't it be better to not blacklist added columns unless specifically blacklisted?

@yajra
Copy link
Owner

yajra commented May 29, 2019

@apreiml it used to be like that and I think it was added on blacklist (for query & eloquent) because a lot of user issues were being raised where added column searching/sorting is not working. Added column for me is a computed column and is not part of the database.

@yajra
Copy link
Owner

yajra commented May 29, 2019

In addition, if you want to search on added columns, that's where filterColumn comes in where we can create a custom filter on how to search the computed column.

@yajra
Copy link
Owner

yajra commented May 29, 2019

Sent a PR #2102. Kindly confirm if it fixes the issue. Works as per my testing though.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants