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
$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);
Thanks for reporting, the only PR I know that have something to do with search is https://github.com/yajra/laravel-datatables/pull/2079. Will try to check this as soon as I can. Ping @apreiml, would you be able to confirm this? Thanks!
Same thing
Guys, would you be able to confirm if reverting #2079 would fix this issue? Will revert the PR if it's the culprit. Thanks!
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
Wouldn't it be better to not blacklist added columns unless specifically blacklisted?
@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.
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.
Sent a PR #2102. Kindly confirm if it fixes the issue. Works as per my testing though.