Your search did not match any results.
File Manager

Toolbar and Context Menu

The FileManager component provides the following UI customization properties:

  • The toolbar property specifies the toolbar's visibility and available commands.
  • The contextMenu property specifies the context menu's availability and its commands.

The toolbar and context menu support context-invariant and context-sensitive items that can be visible or hidden depending on user action.

Backend API
Copy to CodeSandBox
Apply
Reset
import React from 'react'; import FileManager, { Permissions, Toolbar, ContextMenu, Item, FileSelectionItem, ItemView, Details, Column, } from 'devextreme-react/file-manager'; import { fileItems } from './data.js'; class App extends React.Component { constructor(props) { super(props); this.fileManagerRef = React.createRef(); this.newFileMenuOptions = { items: [ { text: 'Create new file', icon: 'plus', items: [ { text: 'Text Document', extension: '.txt', }, { text: 'RTF Document', extension: '.rtf', }, { text: 'Spreadsheet', extension: '.xls', }, ], }, ], onItemClick: this.onItemClick.bind(this), }; this.changeCategoryMenuOptions = { items: [ { text: 'Category', icon: 'tags', items: [ { text: 'Work', category: 'Work', }, { text: 'Important', category: 'Important', }, { text: 'Home', category: 'Home', }, { text: 'None', category: '', }, ], }, ], onItemClick: this.onItemClick.bind(this), }; this.onItemClick = this.onItemClick.bind(this); this.createFile = this.createFile.bind(this); this.updateCategory = this.updateCategory.bind(this); } render() { return ( <FileManager ref={this.fileManagerRef} fileSystemProvider={fileItems} onContextMenuItemClick={this.onItemClick} height={450}> <Permissions create={true} delete={true} rename={true} download={true}> </Permissions> <ItemView showParentFolder={false}> <Details> <Column dataField="thumbnail"></Column> <Column dataField="name"></Column> <Column dataField="category" caption="Category" width="95"></Column> <Column dataField="dateModified"></Column> <Column dataField="size"></Column> </Details> </ItemView> <Toolbar> <Item name="showNavPane" visible="true" /> <Item name="separator" /> <Item name="create" /> <Item widget="dxMenu" location="before" options={this.newFileMenuOptions} /> <Item name="refresh" /> <Item name="separator" location="after" /> <Item name="switchView" /> <FileSelectionItem name="rename" /> <FileSelectionItem name="separator" /> <FileSelectionItem name="delete" /> <FileSelectionItem name="separator" /> <FileSelectionItem widget="dxMenu" location="before" options={this.changeCategoryMenuOptions} /> <FileSelectionItem name="refresh" /> <FileSelectionItem name="clearSelection" /> </Toolbar> <ContextMenu> <Item name="create" /> <Item text="Create new file" icon="plus"> <Item text="Text Document" extension=".txt" /> <Item text="RTF Document" extension=".rtf" /> <Item text="Spreadsheet" extension=".xls" /> </Item> <Item name="rename" beginGroup="true" /> <Item name="delete" /> <Item text="Category" icon="tags" beginGroup="true"> <Item text="Work" category="Work" /> <Item text="Important" category="Important" /> <Item text="Home" category="Home" /> <Item text="None" category="" /> </Item> <Item name="refresh" /> </ContextMenu> </FileManager> ); } get fileManager() { return this.fileManagerRef.current.instance; } onItemClick({ itemData, viewArea, fileSystemItem }) { let updated = false; if (itemData.extension) { updated = this.createFile(itemData.extension, fileSystemItem); } else if (itemData.category !== undefined) { updated = this.updateCategory(itemData.category, fileSystemItem, viewArea); } if (updated) { this.fileManager.refresh(); } } createFile(fileExtension, directory = this.fileManager.getCurrentDirectory()) { const newItem = { __KEY__: Date.now(), name: `New file${fileExtension}`, isDirectory: false, size: 0, }; if (!directory.isDirectory) { return false; } let array = null; if (!directory.dataItem) { array = fileItems; } else { array = directory.dataItem.items; if (!array) { array = []; directory.dataItem.items = array; } } array.push(newItem); return true; } updateCategory(newCategory, directory, viewArea) { let items = null; if (viewArea === 'navPane') { items = [directory]; } else { items = this.fileManager.getSelectedItems(); } items.forEach((item) => { if (item.dataItem) { item.dataItem.category = newCategory; } }); return items.length > 0; } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app'), );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/21.2.3/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import("./index.js"); </script> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
export const fileItems = [{ name: 'Documents', isDirectory: true, category: 'Work', items: [{ name: 'Projects', isDirectory: true, category: 'Work', items: [{ name: 'About.rtf', isDirectory: false, size: 1024, }, { name: 'Passwords.rtf', isDirectory: false, category: 'Important', size: 2048, }], }, { name: 'About.xml', isDirectory: false, size: 1024, }, { name: 'Managers.rtf', isDirectory: false, size: 2048, }, { name: 'ToDo.txt', isDirectory: false, size: 3072, }], }, { name: 'Images', isDirectory: true, category: 'Home', items: [{ name: 'logo.png', isDirectory: false, size: 20480, }, { name: 'banner.gif', isDirectory: false, size: 10240, }], }, { name: 'System', isDirectory: true, category: 'Important', items: [{ name: 'Employees.txt', isDirectory: false, category: 'Important', size: 3072, }, { name: 'PasswordList.txt', isDirectory: false, category: 'Important', size: 5120, }], }, { name: 'Description.rtf', isDirectory: false, size: 1024, }, { name: 'Description.txt', isDirectory: false, size: 2048, }];
window.config = { transpiler: 'plugin-babel', meta: { 'devextreme/localization.js': { 'esModule': true, }, }, paths: { 'npm:': 'https://unpkg.com/', }, defaultExtension: 'js', map: { 'react': 'npm:react@17.0.2/umd/react.development.js', 'react-dom': 'npm:react-dom@17.0.2/umd/react-dom.development.js', 'prop-types': 'npm:prop-types@15.7.2/prop-types.js', 'rrule': 'npm:rrule@2.6.6/dist/es5/rrule.js', 'luxon': 'npm:luxon@1.28.0/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@21.2.3/cjs', 'devextreme-react': 'npm:devextreme-react@21.2.3', 'jszip': 'npm:jszip@3.7.1/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@1.5.5/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.1.37/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@3.1.24/dist/dx-gantt.js', '@devextreme/vdom': 'npm:@devextreme/vdom@2.2.3', '@devextreme/runtime': 'npm:@devextreme/runtime@2.3.8', 'inferno': 'npm:inferno@7.4.10/dist/inferno.min.js', 'inferno-compat': 'npm:inferno-compat@7.4.10/dist/inferno-compat.min.js', 'inferno-create-element': 'npm:inferno-create-element@7.4.10/dist/inferno-create-element.min.js', 'inferno-dom': 'npm:inferno-dom@1.0.7/dist/inferno-dom.min.js', 'inferno-hydrate': 'npm:inferno-hydrate@7.4.10/dist/inferno-hydrate.min.js', 'inferno-clone-vnode': 'npm:inferno-clone-vnode@7.4.10/dist/inferno-clone-vnode.min.js', 'inferno-create-class': 'npm:inferno-create-class@7.4.10/dist/inferno-create-class.min.js', 'inferno-extras': 'npm:inferno-extras@7.4.10/dist/inferno-extras.min.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0.0.25/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js', }, packages: { 'devextreme': { defaultExtension: 'js', }, '@devextreme/vdom': { defaultExtension: 'js', }, 'devextreme-react': { main: 'index.js', }, 'devextreme/events/utils': { main: 'index', }, 'devextreme/events': { main: 'index', }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js', }, }, packageConfigPaths: [ 'npm:@devextreme/*/package.json', 'npm:@devextreme/runtime@2.3.8/inferno/package.json', ], babelOptions: { sourceMaps: false, stage0: true, react: true, }, }; System.config(window.config);