Add Buttons to the Record List Page
Overview
This article introduces how to place a button on Kintone's record list page. The button is placed in the header menu, above the list of records.
Sample Image
In this example, the element in the header menu will be obtained, and a button will be placed inside. Clicking the button will run an alert script.
Sample Code
Prepare the following JavaScript code in a text editor and navigate to the Kintone App's settings. Upload the file into the JavaScript and CSS Customization settings .
|
|
After saving the settings and clicking on Update App, navigate to the Record list page. A button should appear above the list of records.
Code Explanation
Set the index.show event
The app.record.index.show event is set, so that the main code runs when the Record List page is loaded.
|
|
Retrieve the Header Menu Space element
The blank space element in the header menu above the Record List is obtained using the kintone.app.getHeaderMenuSpaceElement() method. A child node is added to this element.
|
|
Create a button element
The button is added to the child element.
|
|
Prevent a duplication bug
Whenever a user clicks on the header of the record list (such as Name or Company in the below image), it reorders the records. This action also triggers the app.record.index.show event. This causes an issue where buttons become duplicated.
To avoid this issue, an if statement is implemented to stop running the script.
|
|
Write the onclick script
When the button is clicked, an alert dialog displays a message.
|
|