How to concatenate fields in Listview

Hello

I’ve created a new module via module builder with a Basic template, but I need only one functional from the Person template - It’s concatenated Name field in ListView

I’ve checked how It created in another test module and it looks like :
…/metadata/listview

'NAME' => array(
    'width' => '20%',
    'label' => 'LBL_NAME',
    'link' => true,
    'orderBy' => 'last_name',
    'default' => true,
    'related_fields' => array('first_name', 'last_name', 'salutation'),

When I trying to do the same with my new module I can’t get success. There is nothing appear, sure I’ve created first_name and last name

Also, I trying add

‘customCode’ => ‘{$fields.first_name.value} {$fields.last_name.value}’,
it’s appear nothing

and

‘customCode’ => ’ {$LAST_NAME} {$FIRST_NAME} ',

The last one works only If I added last name and first name in ListView too

So maybe anybody here knows how can I just make simple concatenated fields in ListView(detailView…)

For example, I wanna just the same function as it is in Contacts module. It has two fieldsfirst_name and last_name in editview and MySQL and only has one field Name in ListView(and detailView) without MySQL, it just contacted first_name and last_name

Use this version :point_up:

but add the other fields as query_only, see example here:

@pgr

thanks for reply

I trying to add this in /custom/modules/mymodule/metadata/listviewdefs.php

add this

  'NAME' =>     (NAME is a default )
  array (
    'width' => '32%',
    'label' => 'LBL_NAME',
    'default' => true,
    'link' => true,
    'customCode' => ' {$LAST_NAME} {$FIRST_NAME}',
  ),

  	'FIRST_NAME' =>
		array (
		    'name'=>'first_name',
			'usage' => 'query_only',
		),

  	'LAST_NAME' =>
		array (
		    'name'=>'last_name',
			'usage' => 'query_only',
		),

I added my firest/last name as a query_only and it doesn’t deny effect

Name column in Listview looks empty

image

What did I wrong?

I don’t know what’s wrong. I guess you’ll have to check the field names with a debugger, and see if the query_only is having the desired effect of producing a query for the subpanels that loads all the necessary fields.

If it is, then you can look in the part where customCode is evaluated to see why it doesn’t get the values for displaying.

Sorry for not being more specific, but I don’t really know the answer, and I won’t have a chance to actually run this and test it in the near future…

1 Like

thanks I’ll be looking for it

1 Like

how to add if condition in the listviewdef?

@bhavin0070

Look at the post:

You can add a custom field type function.