Add Custom Toolbar Item in EJ2 TypeScript File Manager
31 Jan 20265 minutes to read
Use the toolbarItems API to modify the items displayed in the toolbar. When combining default and custom items, assign a unique name to each item so they can be managed independently. Default items can be customized by setting properties such as tooltipText, iconCss, text, suffixIcon, and template.
The example below demonstrates adding a custom checkbox to the toolbar using the template property. It also shows how to modify the default NewFolder item and add a custom toolbar item for selection.
import { FileManager, Toolbar, NavigationPane, DetailsView } from '@syncfusion/ej2-filemanager';
import { CheckBox, ChangeEventArgs } from '@syncfusion/ej2-buttons';
FileManager.Inject(Toolbar, NavigationPane, DetailsView)
let hostUrl: string = 'https://ej2-aspcore-service.azurewebsites.net/';
// initialize File Manager control
let filemanagerInstance: FileManager = new FileManager({
ajaxSettings: {
url: hostUrl + 'api/FileManager/FileOperations',
getImageUrl: hostUrl + 'api/FileManager/GetImage',
uploadUrl: hostUrl + 'api/FileManager/Upload',
downloadUrl: hostUrl + 'api/FileManager/Download'
},
//Custom item added along with default item
toolbarItems: [{ text: 'Create folder', name: 'NewFolder', prefixIcon: 'e-plus', tooltipText: 'Create folder' },
{ name: 'Upload' },
{ name: 'SortBy' },
{ name: 'Refresh' },
{ name: 'Cut' },
{ name: 'Copy' },
{ name: 'Paste' },
{ name: 'Delete' },
{ name: 'Download' },
{ name: 'Rename' },
{ template: '<input id="checkbox" type="checkbox"/>', name: 'Select' },
{ name: 'Selection' },
{ name: 'View' },
{ name: 'Details' }],
height: '380px'
});
// render initialized File Manager
filemanagerInstance.appendTo('#filemanager');
// Render Checkbox in template
var checkbox: CheckBox = new CheckBox({ label: 'Select All', checked: false, change: onChange }, '#checkbox');
// on checkbox change select all or clear selection
function onChange(args: ChangeEventArgs): void {
if (args.checked) {
filemanagerInstance.selectAll();
checkbox.label = 'Unselect All';
}
else {
filemanagerInstance.clearSelection();
checkbox.label = 'Select All';
}
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 File Manager</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 File Manager Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-base/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-inputs/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-popups/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-buttons/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-splitbuttons/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-layouts/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-navigations/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-grids/styles/tailwind3.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/32.1.19/ej2-filemanager/styles/tailwind3.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id="filemanager"></div>
<style>
.e-fe-tick::before {
content: '\e614';
}
</style>
</body>
</html>#container {
visibility: hidden;
}
#loader {
color: #008cff;
height: 40px;
width: 30%;
position: absolute;
top: 45%;
left: 45%;
}