Context Menu
14 Nov 20176 minutes to read
The context-menu has list of items which helps to perform FileExplorer operations, and it appears based on the target such as file or folder.
Context menu items
The below table shows the context menu items corresponding to the location where it is opened:
Context menu location | Context menu items | Screenshot |
---|---|---|
While right click on treeview nodes (from navigation pane) |
* New folder * Upload * Delete * Rename * Cut * Copy * Paste |
|
While right click on File / Folder |
* Open * Download * Upload * Delete * Rename * Cut * Copy * Paste * Get info |
|
While right click on layout (content pane) |
* Refresh * Paste * Sort By * New folder * Upload * Get info |
|
The below table explains the behavior of each context menu item:
Open |
It opens the selected folder. When an image file selected it opens the preview of the image. For the remaining files this option becomes disabled. |
Download |
It downloads the selected file. When a file or number of files selected at that time only download option enabled. If multiple files selected then it downloads all the files in a zip format. |
Cut |
It makes the copy of the selected files or folders into the clipboard. When the user paste the files in any location, the files are removed from the source location. |
Copy |
It makes the copy of the selected files or folders into the clipboard. When the user paste the files, the copy of the files only pasted in the target location. |
Paste |
It paste the files from the clipboard into the current selected folder. Note that when the files are copied into the clipboard at that time only it enabled. |
Delete |
It deletes the current selected file or folder. When you select any file or folder at that time only this option gets enabled. If multiple files selected then it deletes all the selected items. |
Rename |
This is used to rename the current selected file or folder. When you select any file or folder at that time only this option gets enabled. Even multiple files selected it renames the single file only. |
New folder |
It creates a new folder on the current directory. While click on the NewFolder item a dialog appears to get the folder name. Based on the user input, a new folder create on the current directory. |
Upload |
It uploads a file or list of files into the current directory. |
Get info |
It displays the details of the current selected file or folder. |
Sort By |
It's used to sorting the files and folders from the current directory.The sorting can be done based on the columns available from grid,in both ascending and descending order. |
Context menu Visibility
The presence of the context menu can be controlled by the showContextMenu property. This was enabled by default, and by disabling this property you can prevent our built-in context menu.
/// <reference path="tsfiles/jquery.d.ts" />
/// <reference path="tsfiles/ej.web.all.d.ts" />
module ExplorerComponent {
$(function () {
var fileSystemPath = "http://js.syncfusion.com/demos/ejServices/Content/FileBrowser/";
var ajaxActionHandler = "http://js.syncfusion.com/demos/ejServices/api/FileExplorer/FileOperations";
var file = new ej.FileExplorer($("#fileExplorer"), {
path: fileSystemPath,
ajaxAction: ajaxActionHandler,
// hides our built-in context menu
showContextMenu: false
});
});
}
Enable / Disable the Context menu Item
The context menu items can be enabled or disabled through the client side public methods. It enables or disables the item from all the context menu where it is present.
For example, if you disable the “Upload” item, it disables in all places wherever it appears such as open the context menu on treeview, open on file/folder, and open on layout.
These methods only accepts the context menu item name as the parameter.
$(function () {
var fileExpObj = new ej.FileExplorer($("#fileExplorer"), {
});
// this disables the New Folder item
fileExpObj.disableMenuItem("New folder");
// this disables the Download item
fileExpObj.disableMenuItem("Download");
});
Context Menu Events
You would be notified with events when you try to open the context menu items (menuBeforeOpen), after context menu items is opened (menuOpen) and when you click the menu items (menuClick). The following code example illustrates how to define those events.
/// <reference path="tsfiles/jquery.d.ts" />
/// <reference path="tsfiles/ej.web.all.d.ts" />
module ExplorerComponent {
$(function () {
var file = new ej.FileExplorer($("#fileExplorer"), {
menuBeforeOpen: function (args) {
//you add/remove the context menu items in run time
//do your custom action here.
args.dataSource.pop();
},
menuOpen: function (args) {
//you can also identify which context menu is opened by
if (args.contextMenu == "cwd") {
//do your custom action here.
}
},
menuClick: function (args) {
switch (args.text) {
case "largeicons":
//do your custom action here.
break;
}
}
});
});
}