Your search did not match any results.
File Manager

Toolbar and Context Menu

The FileManager widget provides the following UI customization options:

  • The toolbar option specifies the toolbar's visibility and available commands.
  • The contextMenu option 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.

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) { var newItem = { __KEY__: Date.now(), name: `New file${ fileExtension}`, isDirectory: false, size: 0 }; directory = directory || this.fileManager.getCurrentDirectory(); if(!directory.isDirectory) { return false; } var array = null; if(!directory.dataItem) { array = fileItems; } else { array = directory.dataItem.items; if(!array) { directory.dataItem.items = array = []; } } array.push(newItem); return true; } updateCategory(newCategory, directory, viewArea) { var items = null; if(viewArea === 'navPane') { items = [ directory ]; } else { items = this.fileManager.getSelectedItems(); } items.forEach(function(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/20.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.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 }];
System.config({ transpiler: 'plugin-babel', meta: { }, paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16.14.0/umd/react.development.js', 'react-dom': 'npm:react-dom@16.14.0/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.25.0/build/global/luxon.min.js', 'es6-object-assign': 'npm:es6-object-assign@1.1.0', 'devextreme': 'npm:devextreme@20.2.3', 'devextreme-react': 'npm:devextreme-react@20.2.3', 'jszip': 'npm:jszip@3.5.0/dist/jszip.min.js', 'devextreme-quill': 'npm:devextreme-quill@0.9.5/dist/dx-quill.min.js', 'devexpress-diagram': 'npm:devexpress-diagram@2.0.0/dist/dx-diagram.js', 'devexpress-gantt': 'npm:devexpress-gantt@2.0.0/dist/dx-gantt.js', 'preact': 'npm:preact@10.5.5/dist/preact.js', 'preact/hooks': 'npm:preact@10.5.5/hooks/dist/hooks.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-react': { main: 'index.js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, 'es6-object-assign': { main: './index.js', defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });