question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Concatenate two columns in list view

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

14reactions
viktorivanovcommented, Mar 17, 2017

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

2reactions
adbmdpcommented, Mar 17, 2017

It works!! Thank you @viktorivanov

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to concatenate the values of two Columns into One ...
How to concatenate the values of two Columns into One inside ListView ; ListView Name="listView" ItemsSource="{Binding DeviceList}" SelectedItem= ...
Read more >
How To Concatenate Columns In a SharePoint List ... - YouTube
This SharePoint tutorial will demonstrate how to concatenate two columns in a SharePoint list. Specifically, it will demonstrate how to ...
Read more >
how to combine two list column values and show in another list
1. Create a List column with External Content Type. 2. Create another column based on external content type and concatenate State and City....
Read more >
Pandas Concatenate Two Columns - Spark by {Examples}
In this article, I will cover the most used ways in my real-time projects to concatenate two or multiple columns of string/text type....
Read more >
How to Concat Two Columns Into One With the Existing ...
In this article, we will see an SQL query to concatenate two-column into one with the existing column name. We can perform the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found