Complementary to the fantastic video tutorial on how to create a simple button in list view by emillod https://forum.espocrm.com/forum/deve...4465#post74465, here's a guide to create a button on the top of the list display, that will perform custom actions defined through coding and will look like this:
Step 1:
Create a custom view class that will replace the core view class specified for the Contact entity to render the header section of a list display.
client/custom/src/views/contact/list.js
Step 2:
Create a custom clientDefs metadata definition for the Contact entity that will let Espo know that a custom view class is to be invoked for displaying the header in Contact list display.
custom/Espo/Custom/Resources/metadata/clientDefs/Contact.json
Step 3:
Create a custom language file to translate the buttons labels to your preferred language.
custom/Espo/Custom/Resources/i18n/fr_FR/Contact.json
Step 4:
Rebuild application and refresh the page
Step 1:
Create a custom view class that will replace the core view class specified for the Contact entity to render the header section of a list display.
client/custom/src/views/contact/list.js
Code:
define('custom:views/contact/list', 'views/list', function (Dep) { return Dep.extend({ setup: function() { Dep.prototype.setup.call(this); this.setupCustomButtons(); }, setupCustomButtons: function () { this.menu.buttons.unshift({ action: 'myAction1', html: '<span class="fas fa-chess-knight fa-sm"></span> ' + this.translate('Do Something', 'labels', this.scope), style: 'default', acl: 'read', aclScope: this.entityType || this.scope }); this.menu.buttons.push({ action: 'myAction2', html: '<span class="fas fa-chess-rook fa-sm"></span> ' + this.translate('Do Something Else', 'labels', this.scope), style: 'default', acl: 'read', aclScope: this.entityType || this.scope }); }, actionMyAction1: function() { alert("Thank you for your click in button #1"); }, actionMyAction2: function() { alert("Thank you for your click in button #2"); } }); });
Create a custom clientDefs metadata definition for the Contact entity that will let Espo know that a custom view class is to be invoked for displaying the header in Contact list display.
custom/Espo/Custom/Resources/metadata/clientDefs/Contact.json
Code:
{ "views": { "list": "custom:views/contact/list" } }
Create a custom language file to translate the buttons labels to your preferred language.
custom/Espo/Custom/Resources/i18n/fr_FR/Contact.json
Code:
{ "labels": { "Do Something": "faire quelque chose", "Do Something Else": "faire autre chose" } }
Rebuild application and refresh the page
Comment