-
Notifications
You must be signed in to change notification settings - Fork 908
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
Overriding search method to make a column searchable seems to remove my action buttons #1641
Comments
Hello there! Thanks for opening your first issue on this repo! Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that. Backpack communication mediums:
Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch. Thank you! -- |
Yes, same to me. Just looking for the same: Using the search in a table field that is not declared as a column. |
You could add a custom search logic in a column to include other columns in the search, without overriding the search method: $this->crud->addColumn( [
'name' => 'my_field',
'label' => 'My visible column',
'type' => 'text',
'searchLogic' => function ( $query, $column, $searchTerm ) {
$query->orWhere( $column['name'], 'like', '%' . $searchTerm . '%' );
// add other fields
$query->orWhere( 'my_hidden_field', 'like', '%' . $searchTerm . '%' );
}
] ); |
Thanks for the reply :) Yeah that's what I ended up doing in the end and is actually working fairly well. I just thought it was weird in this case to attach unrelated search logic to a random field just to modify the search query. Overriding the search method seemed like a cleaner solution and the fact that the action buttons disappeared definitely seems a bit strange. Thanks, |
Yeah, this is a very good "quick&dirty" solution :) |
@jsvini that’s a nice hack, thank you :-) I think we should provide an official solution to this, since it’s a pretty common scenario. Solution AThe most intuitive solution would probably be to allow developers to add “invisible” columns, that get searched, but aren’t visible in the list view. We could:
So it would be as easy as: $this->crud->addColumn([
'name' => 'description', // The db column name
'label' => “Description", // Table column heading
'visible' => false, // show or hide the column from the list view
]); Solution BA solution with less impact on existing features would be to have something like $this->crud->addColumnToSearch([
'name' => 'description', // The db column name
'label' => “Description", // Table column heading
]); Maybe a better name would be What do you guys think? Any better solutions? |
IMO we shouldn't use any kind of fake column here. I think this is misleading. It never shows up, or do I miss something? Why do we need "label" for this? I tend to something like your Maybe something like this with 3 ways to use: // simple string
$this->crud->addSearchableAttribute('column_name');
// array of simple strings
$this->crud->addSearchableAttribute(['column_name1', 'column_name2']);
// closure for special searches
$this->crud->addSearchableAttribute(function() {...}); |
@tswonke you make a good point... It’s not actually a column, it’s just an attribute you make searchable. |
@tswonke , @scottjs @jsvini I've inadvertently pushed a solution for this yesterday, in the $this->crud->addColumn([
'name' => 'description',
'visibleInTable' => false,
'visibleInModal' => false,
'visibleInExport' => false,
'visibleInShow' => false,
]); and it will be searchable, but show up NOWHERE in the I'll close the issue for now, since we do have a soluton. Let me know if you think it's not a particularly good one, and we'll create a PR to add Cheers! |
Fixes #1641 - added visibleInShow attribute to columns
Bug report
I want to make a column searchable in the CRUD panel but not show it in the list of columns. I found some notes here that appears to allow me to use
$this->crud->addColumn()
to append additional columns to the search.However, when I do this my action buttons seem to get replaced with this custom column and I'm not sure why.
What I did:
What I expected to happen:
No visible changes to the column view but allows the search field to also search for the primary contact name.
What happened:
The action buttons were removed and replaced with my custom column instead.
Before:
After:
What I've already tried to fix it:
Overriding the entire search method to see if it's an ordering issue, but I'm not able to work out how this works internally to try other things.
Backpack, Laravel, PHP, DB version:
Backpack: 3.4
Laravel: 5.6
PHP: 7.1.20
The text was updated successfully, but these errors were encountered: