SolvedCRUD Concatenate two columns in list view

I would like to concatenate two columns in my list view.
I want to have "firstname name".

So i did an accesor in my model:

public function getFullNomAttribute() {
    return $this->firstname . ' ' . $this->name;
}

And in my controller:

 $this->crud->addColumn([ 
            'label' => "concatened_name", 
            'type' => "model_function",
            'function_name' => 'getFullNomAttribute',
        ]);

It's working as long as i have the two columns defined with addColumn in my controller:

 $this->crud->addColumn([
            'name' => 'name',
            'label' => "name",
            'type' => 'text'
        ]);
        $this->crud->addColumn([
            'name' => 'firstname',
            'label' => "firstname",
            'type' => 'text'
        ]);

But i end up with three columns: firstname, name and concatened_name
And if i remove the two addColumn my accesor is not working anymore...
I want just concatened_name in my list.

Any idea ? Thanks!

19 Answers

βœ”οΈAccepted Answer

Here's what you can do to make your attribute show when enableAjaxTable() is present on your CRUD:

  1. Add your attribute on the model
public function getFullnameAttribute() 
{
    return $this->first_name . ' ' . $this->last_name;
}
  1. Make a 'helper' function that will return your accessor through a fresh instance of the current entry
public function showFullname()
{
    return $this->fresh()->fullname; // make sure you call fresh instance or you'll get an error that fullname is not found or something like that...
}
  1. On your CRUD controller in setUp add your column using the function from above
$this->crud->addColumn([
    'label' => 'Full name',
    'type' => 'model_function',
    'function_name' => 'showFullname'
]);

That's it

Related Issues:

29
CRUD [Feature] Ability to define any (nested) fields inside "table" field
I did something very similar to this implemented a field following the table field default and creat...
16
CRUD How to customize search query?
:-)) hi @nathanielks Glad to hear the package gave was a nice surprise to you Well ...
14
CRUD Concatenate two columns in list view
Here's what you can do to make your attribute show when enableAjaxTable() is present on your CRUD: A...
12
CRUD ReflectionException Class translator does not exist
It seems this has to do with calling trans() in config files which is apparently not possible in lar...
7
CRUD Pagination using AJAX
Hi guys I've just finished AJAX pagination Is this considered? Right now all rows are queried ...
4
CRUD Bug image field, store in fake field (store as base64, not path)
Hi everyone Allow me to post this to this closed topic It could be useful to someone Looking for a s...
4
CRUD Laravel Backpack FIlter Not Called
Thx that solved the problem for me: Solution (working for Laravel >= 5.5) Configure App\Http\Middlew...
3
CRUD Upload field type on edit required issue
I know this is a closed issue but I found this after searching for a solution for a similar issue I ...
3
CRUD Return with Validator errors
Hi @OSDDQD This has happened to me before for custom CRUD entities when I applied the web middleware...
288
ngx admin No PostCSS Config found with build:prod
Or you can create a file named postcss.config.js in root directory Just leave it empty or write the ...
66
react admin Error: Invariant failed: You should not use <Route> outside a <Router>
Just remember: Before using {Route} from 'react-router-dom' library just make sure you put <Route> i...
59
EasyAdminBundle Multiple file/images upload - OneupUploaderBundle
I got this to work with VichUploaderBundle Is there any possibility to manage upload multiple files?...
58
react admin ra-data-graphql-simple shows error when plugged to apollo-server
I also encountered the issue and actually that's not a bug of React Admin but a React Hook misuse :)...
44
AdminLTE Active menu item with multi level submenus
nice script but it is not valid where you took the class ul.level-1 from? πŸ˜„ AdminLTE doesn't use so...
39
ngx admin Add JWT automatically for every HTTP request
FYI if you are using this solution check out my other reply: #1375 (comment) I couldn't get this to ...
34
react admin display array with arrayField or other
I cannot comprehend why this has been essentially wontfixed There is nothing at all strange about an...
28
AdminLTE Sidebar menu treeview not working after redirection in Angular 4
This problem in Angular 6 and AdminLTE 3 was solved as follows: Note: I have a Sidebar component tha...
27
laravel filemanager Error when accessing /laravel-filemanager
In lfmhelpers.php line 335 replace the return with this: and in vendor/unisharp/laravel-filemanager/...
25
coreui free react admin template Deploy build to Nginx give error Uncaught SyntaxError: Unexpected token <
@thangnvse try this adding this into your nginx conf Step: npm run-script build Copy built files to ...
24
react admin Deprecated findDOMNode warning in StrictMode - originating from react-transition-group
Any timeline on this issue? We are using react-admin for an admin panel for our client and want to e...
13
AdminLTE How to remember the toggle state of the sidebar menu?
I've fixed the external Script with this is your 1 question answered :) i missed this on exporting i...
12
EasyAdminBundle Is there anything new to use translatable entities?
While preparing to upgrade to SF4 and Flex I had a go at this: Integrating KnpLabs/DoctrineBehaviors...
12
react admin Typescript declarations
Thanks I'll start writing types for next and post them in DefinitelyTyped Hi ...
12
react admin Pagination fails with *TypeError: onChangePage is not a function*
I think I found a workaround for the time being Using yarn in my package.json I added this resolutio...
11
react admin [RFC] Embedded Arrays using FieldArray
Nice! I think this could make it to the core But I'd prefer that subrecords are displayed as lines r...
5
Serenity Sum of column in Detail Dialog - Shown/calculated immediately in a field of Parent Dialog
Here is a sample for you for OrderDialog constructor: Replace Q.notifySuccess with form.MyField.valu...
4
ant design pro πŸ›[BUG] Login doesn't work properly if /api/currentUser route is protected
I can also confirm that I've been hit by this It's much simpler to reproduce also ...
4
Serenity How to implement TreeView by SlickGrid in Serenity
It took me an hour to figure out how to turn default EntityGrid (generated by sergen) to a Tree List...
3
EasyAdminBundle After manual deleting cache got error
Hello Hours debugging helps figure out what's going on How to reproduce: Step 1 Install profiler ...
3
Serenity Back to use of AD credentials
@Solabar sorry I didn't get a chance to update this Some dudes here have resolved their issues and w...
3
Serenity [Please Comment] Inquiry about switching to TypeScript
Here is some update and proof of concept for TypeScript / Saltaralle interop: In ts-experiments bran...
98
axios module How to set query params and message body?
No I don't mean the baseURL but the url path As an example let's say I have the following call: Axio...
34
axios module How to import module to external file
@lukasborawski I think the following solution is far more elegant So let's say that I'm using axios ...
26
october Reorder of records in relation
@canthis thank you very much the references you gave pointed me in the right direction and I was abl...
20
axios module baseURL settings do not take effect for axios
it worked for me adding require('dotenv').config() to the nuxt.config.js Version v5.1.0 Reproduction...
19
parse server Parse Live Query don't work on AWS elasticbeanstalk
I had this problem recently I am using amazon elastic beanstalk with the parse server and for the pa...
16
parse server useMasterKey in cloudCode not working as expected
Much like how Parse.User.current() is invalid in a node script because of the global nature so is Pa...
14
parse server MongoError: Transaction numbers are only allowed on storage engines that support document-level locking
+1 I had this error until I added retryWrites=false to my database uri. I updated my parse server in...
13
october [feature] Selectable Repeater field Groups
Feature is approaching completion You may test by cloning the October develop branch ...
13
python dotenv Does not load from current directory
I'm running into the same issue on my Ubuntu server with Python 2.7 (had no problems in my local env...
12
parse server Request.user undefined and no information in request
I figure it out why request.user is undefined when calling Cloud function I'm trying to access a use...
8
parse server v2.2.4 Deploy failing on Amazon Elastic Beanstalk
2.2.4 works for me (multiple deployments so far) This is my setup: It was failing for me first becau...
7
parse server How to deploy a scalable Parse LiveQuery Server?
Here is our way to setup scalable Parse LiveQuery server on Heroku Because there is one and only 'we...
6
axios module Loading url in SSR fails, while all works on client side
Another problem is that in SSR mode it's not making a direct request to the data server but calling ...
6
parse server Parse Server Unauthorized Error
After a few rounds of trials and failures I finally got it working Your answer did really help a lot...
5
october Add 3 and 4 column support in backend
No problem will rewrite the code now on that Done - updated code and doc's. Summary of the PR This i...
4
october Backend pages wont open for new administrators
@Morsusy2k it will That's why it's called monkey patch πŸ˜„ Don't think so I'll dig deeper to get this...
4
parse server [PROPOSAL/DISCUSSION] AWS DynamoDB support
for now most tests are passing for Parse.Query the falling tests are expected to fail because of the...
3
lumber Install forest-admin plugin fails: self signed certificate in certificate chain
Hi @Sorok-Dva thank you for contributing! πŸ‘ I just released Lumber a few minutes ago ...