This is a migrated thread and some comments may be shown as answers.

get_gridContextMenu() null after refresh()

9 Answers 168 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
lordscarlet
Top achievements
Rank 1
lordscarlet asked on 31 Mar 2011, 03:50 AM
I have come at this from several directions, but here is what I seem to be down to:

I am using a custom content provider.

I have a gridcontextmenu item that opens a radwindow for editing of file properties. I can open this window, make changes, save them, close the window and everything works fine. 

function gridContextMenuClicked(toolbar, args) {
    var buttonValue = args.get_item().get_value();
        if (buttonValue == "properties_Menu") {
 
        var explorer = $find("<%= RootFileExplorer.ClientID %>");
        var selectedItem = explorer.get_selectedItem();
        if (selectedItem) {
            var itemPath = selectedItem.get_path();
 
            ShowPropertiesDialog(itemPath);
        }
    }
}

One thing that I do is to refresh the explorer OnWindowClose.

function OnWindowClose(sender, args) {
    RefreshExplorer();
 
}
 
function RefreshExplorer() {
    var explorer = $find("<%= RootFileExplorer.ClientID %>");
    explorer.refresh();
}

This has no problems.

To attach the click handler I use some code I found in the KB (I believe).

function OnClientLoad(explorer, args) {
    attachHandlers(explorer);
    explorer.add_ajaxRequestEnd(function () { attachHandlers(explorer); });
}
 
 
function attachHandlers(explorer) {
             
    var gridContextMenu = explorer.get_gridContextMenu();
    gridContextMenu.add_itemClicked(gridContextMenuClicked);
 
    var tree = explorer.get_tree();
    tree.add_contextMenuItemClicked(treeContextMenuClicked);
 
}

This code also functions. 

Here is where the problem occurs. I have also created several "filters" outside of the FileExplorer. They are simple controls, such as a DropDownList and a TextBox used to filter the results of my content provider. To force refresh of the FileExplorer I am clearing the nodes on Page_Load. I tried to find a solution for days, and this is the only way I was able to get both the grid and the tree to refresh.

RootFileExplorer.TreeView.Nodes.Clear();

The result of this seems to be that when the attachHandlers javascript method is called, explorer.get_gridContextMenu() returns null. This obviously throws an error and the whole thing fails. If I don't have it do the attachHandlers() the context menu in my grid no longer works.

I brought up this problem in another thread. The responder (who I just saw as I looked for the thread -- I did not receive an email even though I am subscribed) mentions sending my code. It would not be possible to get a distributable, packaged version of the content provider and other code in any sort of timely manner. Hopefully the details I have provided above will be enough to shed some light.

9 Answers, 1 is accepted

Sort by
0
lordscarlet
Top achievements
Rank 1
answered on 31 Mar 2011, 04:13 AM
Correction: TreeView.Nodes.Clear() is not causing the refresh of the tree. I set my fitlers in Page_Load(). This causes the tree to rebind, I assume it has to do with the ContentProvider, but it is not particularly clear based on the documentation provided. I attempted to change the filters in OnClick()/etc from my filter, but those appeared to occur to late, as the tree remained unaffected. So instead, I have to check the values of my form fields on every page load.

if (Convert.ToInt32(ClientFilter.SelectedValue) >= 0) {
    Session["ClientId"] = ClientFilter.SelectedValue;
    filterView.ClientId = int.Parse(Session["ClientId"].ToString());
} else {
    Session["ClientId"] = null;
    filterView.ClientId = 0;
}
 
Session["ExcludeWithClient"] = ExcludeWithClient.Checked;
filterView.ExcludeWithClient = (bool)Session["ExcludeWithClient"];
 
filterView.SearchKeyword = Keyword.Text;
 
Session["PageInventorySessionFilter"] = filterView;

A peak at the content provider:

public InventoryFileSystemContentProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
    : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag) {
}
public override Telerik.Web.UI.Widgets.DirectoryItem ResolveRootDirectoryAsTree(string path) {
    return GetDirectory(path);
}
 
public override Telerik.Web.UI.Widgets.DirectoryItem ResolveDirectory(string path) {
    return GetDirectory(path);
}
 
private DirectoryItem GetDirectory(string path) {                             
    InventoryFilterView filter = (InventoryFilterView)this.Context.Session["PageInventorySessionFilter"];
    Folder folder = Folder.GetFolderFromPath(path, filter);
 
    List<DirectoryItem> subfolders = GenerateDirectoryItems(folder.SubFolders);
    List<FileItem> files = GenerateFileItems(folder.Files);
 
    return new DirectoryItem(folder.Name, string.Empty, folder.FullPath, string.Empty, PathPermissions.Read, files.ToArray(), subfolders.ToArray());
}
 
private List<DirectoryItem> GenerateDirectoryItems(Folders subFolders) {
    List<DirectoryItem> folders = new List<DirectoryItem>();
    foreach (Folder sub in subFolders) {
        DirectoryItem item = new DirectoryItem(sub.Name, string.Empty, sub.FullPath, string.Empty, PathPermissions.Read, new FileItem[0], new DirectoryItem[0]);
        folders.Add(item);
    }
 
    return folders;
}
 
private List<FileItem> GenerateFileItems(Files folderFiles) {
    List<FileItem> files = new List<FileItem>();
    foreach (File file in folderFiles) {
        FileItem item = new FileItem(file.Name, file.Name.Split('.')[file.Name.Split('.').Length - 1], 0, string.Empty, string.Empty, string.Empty, PathPermissions.Read);
        item.Attributes.Add("Owner", file.OwnerName);
        item.Attributes.Add("Expiration", file.ExpirationDate.ToShortDateString());
        item.Attributes.Add("Deleted", file.IsDeleted.ToString());
        item.Attributes.Add("Client", file.ClientName);
                    
        files.Add(item);
    }
 
    return files;
}

So the problem seems to be something like this:

The grid and tree refresh because of a change to the criteria in the content provider. Truthfully, I'm not really sure how that is happening. I am not specifically triggering a refresh, I am merely changing the criteria that the content provider uses. However this refresh is performed it is damaging the grid object so that the contextmenu is destroyed. If I merely call the .refresh() method via javascript, that data is not lost.
0
Dobromir
Telerik team
answered on 01 Apr 2011, 05:22 PM
Hi Doug,

I am not quite sure I understand the exact problem.

I will try to explain in more details some of the methodologies that you have used:
  • Assigning handlers on the ajaxRequestEnd - this is required only for the handlers that will be assigned to the TreeView, because the TreeView's client-side object is entirely recreated on AJAX and the previously assigned handlers are lost. This is not required for the Grid's context menu - you can assign the gridContextMenu handler in the RadFileExplorer's ClientLoad event.
  • Clearing TreeView's Nodes collection - this is actually forcing the TreeView to reload all its folders, because in case where RadFileExplorer's current folder is not the ROOT folder, the ResolveRootDirectoryAsTree() method of the content provider is called only for the current folder and not repopulating parent folders and sibling folders, thus will not apply any sort of filtering.

I have prepared a sample page according to the explanation of the scenario but was unable to reproduce the problem on my end. Could you please modify the attached page to a point where the problem occurs and send it back so we can investigate it further.
Greetings,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
lordscarlet
Top achievements
Rank 1
answered on 01 Apr 2011, 09:16 PM
I have made some adjustments based on your code, but for some reason it is not behaving the same. When it calls 
var gridContextMenu = expolorer.get_gridContextMenu();

gridContextMenu is null. I haven't been able to figure out any significant differences, but I'm still looking. Is it possible it has to do with how I am creating my custom contextmenu item? I have disabled all of the standard items, and this is the only one I have:

RadMenuItem propertiesMenuItem = new RadMenuItem("Properties");
propertiesMenuItem.Value = "properties_Menu";
RadMenuItem exportMenuItem = new RadMenuItem("Export");
exportMenuItem.Value = "Export";
 
RadTreeViewContextMenu treeViewContextMenu = new RadTreeViewContextMenu();
treeViewContextMenu.Items.Add(exportMenuItem);
 
RootFileExplorer.GridContextMenu.Items.Add(propertiesMenuItem.Clone());
RootFileExplorer.TreeView.ContextMenus.Add(treeViewContextMenu);
RootFileExplorer.TreeView.ContextMenuItemClick += new RadTreeViewContextMenuEventHandler(TreeView_ContextMenuItemClick);

I am still digging through the code, but if you could let me know if this could be the problem that would be greatly appreciated.

Also, your code works as expected.
0
lordscarlet
Top achievements
Rank 1
answered on 01 Apr 2011, 09:26 PM
Yes, that is it. I removed my custom contextmenu and enabled copy, and it works fine. Am I doing something wrong in the way I create my custom context menu item?
0
Dobromir
Telerik team
answered on 04 Apr 2011, 12:48 PM
Hi Doug,

The creation of the Grid's custom context menu items looks OK, however, from the provided code sample, I noticed that you are actually adding a new context menu to the TreeView instead of using its default context menu. Also, the disabling of the default context menus is missing in the provided code, could you please provide the code responsible for the removal of the default menus?

In addition, an examples of how to add a custom context menu and remove commands from the default menus are available in the following help article and KB article:
Adding a custom button to the toolbar and an item to the tree context menu
Remove the "Delete" and "Upload" commands from the RadFileExplorer control  

Since it is not possible to provide a sample project that reproduces the issue, could you please modify the sample page from my previous answer to the point where the problem occurs and send it back so we can investigate it further?

Regards,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
lordscarlet
Top achievements
Rank 1
answered on 04 Apr 2011, 01:35 PM
To remove the default options I am simply using: 

<telerik:RadFileExplorer runat="server" ID="RootFileExplorer"
    EnableOpenFile="false" EnableCopy="false" EnableCreateNewFolder="false" Width="100%"
    OnClientLoad="OnClientLoad">
    <Configuration ViewPaths="~/ROOT" />
</telerik:RadFileExplorer>


I will check what I am doing differently from the provided link. If that does not solve the problem, I will modify the page you provided to see if I can get it to perform as my version does.

EDIT: Actually, it looks like the new context menu is only for the TreeView. If I remove the TreeView context item and simply do the grid one, it still gets the errors. I will see if I can reproduce the error on your sample.
0
lordscarlet
Top achievements
Rank 1
answered on 04 Apr 2011, 04:45 PM
It looks like this convoluted method of removing the context menu items fixes the problem. I was simply removing them before by setting the proper parameters for the control, but that is what was breaking it. Stepping through the Items collection and removing them in the code behind seems to correct the issue.
0
Dobromir
Telerik team
answered on 05 Apr 2011, 01:16 PM
Hi Doug,

I am glad that I was able to help narrowing down the source of the problem. Please, do not hesitate to contact us again if you need further assistance.

All the best,
Dobromir
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rohan
Top achievements
Rank 1
answered on 18 Jul 2012, 01:57 PM
Hi all ,
I want disable the grid context menu of telelrik file explorer. when user click to grid context menu i want check certain condition and then display the context menu. to do this task i need to get grids selected item details with selected item path. how can i do this,
please provide any hint for solution .
Tags
FileExplorer
Asked by
lordscarlet
Top achievements
Rank 1
Answers by
lordscarlet
Top achievements
Rank 1
Dobromir
Telerik team
Rohan
Top achievements
Rank 1
Share this question
or