+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Setting a Default Filter for Library Items in Sitefinity CMS

by Stefani Tacheva
In Documents & Files/Images/Videos sections in Sitefinity CMS when a library is selected you have the ability to filter its item by clicking Filter.. link available in the sidebar section of the backend view. At the moment when a user clicks the filter link he/she will be redirected to a page where all items for the currently selected library are displayed. If you want to set a default filter for these items and display for example the current user's items you need to change the default LibrariesMasterExtensions java script file with a new java script file where this filter is applied.

In the sample below we will set a default filter for Documents & Files libraries and will display only the items of the current user (Instead of All items, My items filter will be set by default). In order to implement this functionality you need to follow the steps below:

1. Open your project in Visual Studio and create a new Java Script file.
2. Place the following source code inside the java script file:

var masterGridView;
var sidebar;
var contextBar;
var toolbar;
var moreActionsMenu;
var queryParams;
var myUserId;
  
  
// called by the MasterGridView when it is loaded
function OnMasterViewLoaded(sender, args) {
    // the sender here is MasterGridView
    masterGridView = sender;
    sender.add_itemCommand(handleMasterGridViewItemCommand);
    myUserId = sender._currentUserId;
    sidebar = sender.get_sidebar();
    contextBar = sender.get_contextBar();
    toolbar = sender.get_toolbar();
    moreActionsMenu = getMoreActionsMenu();
  
    var binder = sender.get_binder();
    binder.add_onItemDataBound(handleBinderItemDataBound);
    binder.add_onDataBound(handleBinderDataBound);
    binder.add_onItemSelectCommand(itemSelectHandler);
    binder.set_unescapeHtml(true);
  
    var itemsGrid = sender.get_currentItemsList();
    itemsGrid.applyFilter("Owner == (" + myUserId + ")");
    itemsGrid.add_command(handleItemsGridCommand);
    itemsGrid.add_beforeCommand(handleItemsGridBeforeCommand);
    itemsGrid.add_itemCommand(handleItemsGridItemCommand);
    itemsGrid.add_dialogClosed(handleItemsGridDialogClosed);
  
    var translationHandlers = { create: editTranslationHandler, edit: editTranslationHandler };
    itemsGrid.set_translationHandlers(translationHandlers);
    var notTranslatedItemsToHide = ".sfRegular,.sfMedium"; //hides "Actions" "File/Dim./Size" "Album/Categories/Tags" "Uploaded/Owner" columns
    itemsGrid.set_itemsToHideSelector(notTranslatedItemsToHide);
    var itemTitleSelector = ".sf_binderCommand_editMediaContentProperties";
    itemsGrid.set_itemTitleSelector(itemTitleSelector);
  
    queryParams = new Telerik.Sitefinity.Web.SitefinityJS.Utility.Querystring();
  
    var folderId = queryParams.get("folderId", null);
    var widget = masterGridView.get_sidebar().getWidgetByName("FolderFilter");
  
    if (folderId && widget) {
        widget.set_selectedItemId(folderId);
        widget.getBinder().set_uiCulture(itemsGrid.getBinder().get_uiCulture());
        widget.getBinder().add_onDataBound(function () { widget.getBinder().setSelectedValues([folderId], true, true); });
    }
    else {
        var libraryId = masterGridView.get_parentId();
        if (libraryId && widget) {
            widget.set_selectedItemId(libraryId);
            widget.getBinder().add_onDataBound(function () { widget.getBinder().setSelectedValues([libraryId], true, true); });
        }
    }
  
    var displayMode = queryParams.get("displayMode", null);
    configureDisplayMode(displayMode);
}
  
function handleItemsGridBeforeCommand(sender, args) {
    switch (args.get_commandName()) {
        case "editFolder":
            var folderId = queryParams.get("folderId", null);
            var dataObject = { Id: folderId };
            var argument = {};
            if (sender.get_uiCulture())
                argument.language = sender.get_uiCulture();
            sender.openDialog('editFolder', dataObject, sender._getDialogParameters('editFolder'), dataObject, argument);
            args.set_cancel(true);
            break;
        case "changeLanguage":
            var widget = masterGridView.get_sidebar().getWidgetByName("FolderFilter");
            widget.getBinder().set_uiCulture(args.get_commandArgument());
            break;
        default:
            break;
    }
}
  
function handleItemsGridCommand(sender, args) {
    switch (args.get_commandName()) {
        case "filterByStorage":
            var filterExpression = "BlobStorageProvider==\"" + args.get_commandArgument().get_dataItem().Name + "\"";
            sender.applyFilter(filterExpression);
            break;
        case "dynamicWidgetItemDataBound":
            var dataItem = args.get_commandArgument().get_dataItem();
            var element = args.get_commandArgument().get_itemElement();
            var jthumbImg = $(element).find(".thumbnailImg");
            if (dataItem.ThumbnailUrl != "") {
                jthumbImg.attr("src", dataItem.ThumbnailUrl);
                if (jthumbImg && jthumbImg.length > 0) {
                    resizeImage(jthumbImg, dataItem.Width, dataItem.Height, 32);
                }
            }
            else {
                jthumbImg.hide();
            }
            break;
        case "selectAll":
            var binder = $find(sender.get_binderId());
            if (binder.selectAll) {
                binder.selectAll();
            }
            break;
        case "deselectAll":
            var binder = $find(sender.get_binderId());
            if (binder.deselectAll) {
                binder.deselectAll();
            }
            break;
        case "showAllItems":
        case "showMyItems":
        case "showDraftItems":
        case "showPublishedItems":
        case "filter":
        case 'customDateFilterCommand':
            {
                var cmdArg = args.get_commandArgument();
                if (cmdArg.hasOwnProperty("propertyToFilter") && cmdArg.propertyToFilter == "LastModified") {
                    var filterExpression = '(LastModified>(' + cmdArg.dateFrom + ') OR Page.LastModified>(' + cmdArg.dateFrom + '))';
                    sender.applyFilter(args.get_commandArgument().filterExpression);
                }
                else {
                    sender.applyFilter(args.get_commandArgument().filterExpression);
                }
                args.set_cancel(true);
            }
            break;
        case 'reorder':
            sender.openDialog('reorder', args.get_commandArgument(), sender._getDialogParameters('reorder'), null);
            break;
        case 'libraryPermissions':
            sender.openDialog('libraryPermissionsDialog', args.get_commandArgument(), sender._getDialogParameters('libraryPermissionsDialog'), null);
            break;
        case "editLibraryProperties":
            var dataItem = args.get_commandArgument();
            var dataObject;
            if (dataItem) {
                dataObject = { Id: dataItem.Id };
            }
            else {
                dataObject = { Id: sender.get_parent().get_parentId() };
            }
            sender.executeCommand("editLibraryProperties", dataObject, dataObject, null, null);
            args.set_cancel(true);
            break;
        case "uploadFile":
            var params = sender._getDialogParameters("upload");
            var folderId = queryParams.get("folderId", null);
            sender.openDialog("upload", { FolderId: folderId }, params, null, null);
            args.set_cancel(true);
            break;
        case "deleteLibrary":
            var dataItem = args.get_commandArgument();
            var key;
            if (dataItem) {
                key = dataItem.Id;
            }
            else {
                key = sender.get_parent().get_parentId();
            }
  
            var deleteFunc = function (sender, args) {
                var commandName = args.get_commandName();
                if (commandName == 'cancel') {
                    return;
                }
  
                var sdr = args.get_commandArgument();
                var originalSericeUrl = sdr.get_serviceBaseUrl();
  
                var parentServices = {
                    "ImageService.svc/": "AlbumService.svc/",
                    "VideoService.svc/": "VideoLibraryService.svc/",
                    "DocumentService.svc/": "DocumentLibraryService.svc/"
                };
  
                var libraryServiceUrl;
                for (var originalSvc in parentServices) {
                    var index = originalSericeUrl.indexOf(originalSvc);
                    if (index > -1) {
                        libraryServiceUrl = originalSericeUrl.substring(0, index) + parentServices[originalSvc];
                        break;
                    }
                }
  
                var urlParams = {};
                var providerName = queryParams.get("provider", null);
                if (providerName) {
                    urlParams.provider = providerName;
                }
  
                var clientManager = sdr.getBinder().get_manager();
                clientManager.InvokeDelete(libraryServiceUrl, urlParams, [key], function () {
                    sdr.applyFilter("");
                    sdr.dataBind();
                },
                function (response) {
                    alert(response.Detail);
                });
            }
  
            var dialog = sender.getPromptDialogByName("confirmDeleteSingle");
            var multipleItemsDeleteCommandButtonId = dialog._commands[1].ButtonClientId;
            var multipleItemsDeleteButton = jQuery('#' + multipleItemsDeleteCommandButtonId);
            multipleItemsDeleteButton.attr("style", "display: none !important");
            dialog.show_prompt('', '', deleteFunc, sender);
            break;
        case "deleteFolder":
            var folderId = queryParams.get("folderId", null);
            if (folderId) {
                sender.deleteItems([folderId]);
            }
            break;
        default:
            break;
    }
}
  
function handleItemsGridItemCommand(sender, args) {
    switch (args.get_commandName()) {
        case "filter":
            var dataItem = args.get_commandArgument();
            sender.applyFilter("Parent.Id == " + dataItem.ParentId);
            break;
        default:
            break;
    }
}
  
//_handleCommand: function (sender, args) {
//    var commandName = args.get_commandName();
//    if (commandName == "createAndUpload") {
//        var workflowOperationName = args.get_commandArgument();
//        this._detailFormView._multipleSaving = false;
//        this._detailFormView.saveChanges(workflowOperationName);
//        args.set_cancel(true);
//    }
//}
  
function handleItemsGridDialogClosed(sender, args) {
    var context = null;
    if (args && args.get_context) {
        context = args.get_context();
    }
  
    if (context && context.get_widgetCommandName && context.get_widgetCommandName() == "createAndUpload") {
        var key = null;
        var params = sender._getDialogParameters("upload", args.get_dataItem());
        params.LibraryId = args.get_dataItem().Id;
        if (args.get_dataItem().ParentId) {
            params.FolderId = args.get_dataItem().Id;
        }
        sender.openDialog("upload", args.get_dataItem(), params, key, null);
    }
  
    if (context && context.WindowName == "selectLibrary") {
        var itemsGrid = sender;
        var binder = itemsGrid.getBinder();
        var clientManager = binder.get_manager();
        var serviceBaseUrl = binder.get_serviceBaseUrl();
        var serviceUrl = null;
        var index = serviceBaseUrl.indexOf(".svc");
        if (index > -1) {
            serviceUrl = serviceBaseUrl.substring(0, index + 4) + "/batch/";
  
            var urlParams = [];
            urlParams["provider"] = binder.get_provider();
            urlParams["itemType"] = context.ItemType;
            urlParams["parentItemType"] = context.ParentItemType;
            var parentId = context.Id;
            var keys = [];
            keys.push(parentId);
            var selectedItems = itemsGrid.get_selectedItems();
            var selectedKeys = [];
            var length = selectedItems.length;
            while (length--) {
                var dataItem = selectedItems[length];
                selectedKeys.push(dataItem.Id);
            }
  
            clientManager.InvokePut(serviceUrl, urlParams, keys, selectedKeys, successCallback, failureCallback, sender);
        }
    }
    else {
        //event canceled - return
        return false;
    }
}
  
function successCallback(caller, resultData) {
    // rebind the grid
    caller.dataBind();
}
  
function failureCallback(result) {
    alert(result.Detail);
}
  
function handleMasterGridViewItemCommand(sender, args) {
    var commandName = args.get_commandName();
    var dataItem = args.get_dataItem();
    var mediaUrl = dataItem.MediaUrl;
  
    switch (commandName) {
        case "viewOriginalImage":
        case "viewOriginalDocument":
            window.open(mediaUrl, "_blank");
            break;
        case "download":
            var appender = "?";
            if (mediaUrl.indexOf('?') > 0) { appender = "&"; }
            document.location.href = mediaUrl + appender + "download=true";
            break;
        case "stop-task":
        case "restart-task":
            var itemsGrid = sender;
            var binder = itemsGrid.get_binder();
            var clientManager = binder.get_manager();
            var serviceUrl = itemsGrid.get_baseUrl() + "Sitefinity/Services/Content/LibraryRelocationService.svc/taskcommand/?command=" + commandName + "&taskId=" + dataItem.TaskInfo.TaskId;
            var keys = [];
            var selectedKeys = [];
            var urlParams = [];
            clientManager.InvokePut(serviceUrl, urlParams, keys, selectedKeys, successTaskCommandCallback, null, sender);
            break;
        case "openLibrary":
            var query = new Telerik.Sitefinity.Web.SitefinityJS.Utility.Querystring();
            query.set("folderId", dataItem.Id);
            var uiCulture = sender.get_binder().get_manager().get_uiCulture();
            if (uiCulture) {
                query.set("lang", uiCulture);
            }
            location.search = query.toString(true);
            break;
    }
}
  
function successTaskCommandCallback(caller, resultData) {
    // rebind the grid
    caller.get_itemsGrid().dataBind();
}
  
function handleBinderDataBound() {
    if (typeof masterGridView != 'undefined') {
        var grid = $(masterGridView.get_element());
        var gridTable = $(grid).find(".rgMasterTable");
        var dlgSidebar = null;
        var dlgContent = null;
        var dlgMain = null;
        var wndWidth = null;
        if (gridTable.is(":visible")) {
            var gridWidth = gridTable.width();
  
            if (gridWidth + 80 > $(window).width() * 0.8) {
                //if the content is wider than the viweport
                dlgSidebar = $(".sfSidebar");
                dlgContent = $(".sfContent");
                dlgMain = $(".sfMain");
  
                dlgContent.width(gridWidth + 80);
                dlgSidebar.width(Math.floor(dlgContent.width() / 4));
                wndWidth = dlgSidebar.width() + dlgContent.width();
                dlgMain.width(wndWidth);
                $("body").width(wndWidth);
            }
        }
        if ($("body").width() < $(window).width()) {
            //if the window is resized from smaller to wider
            dlgSidebar = $(".sfSidebar");
            dlgContent = $(".sfContent");
            dlgMain = $(".sfMain");
  
            dlgContent.width("80%");
            dlgSidebar.width("20%");
            wndWidth = dlgSidebar.width() + dlgContent.width();
            dlgMain.width("auto");
            $("body").width("auto");
        }
  
        var contextActionMenu = getContextActionMenuWidget();
        if (contextActionMenu) {
            var folderId = queryParams.get("folderId", null);
            if (folderId) {
                jQuery(contextActionMenu.get_element()).find(".sf_NotForFolder").parent().hide();
            }
            else {
                jQuery(contextActionMenu.get_element()).find(".sf_ForFolder").parent().hide();
            }
        }
    }
}
  
function getContextActionMenuWidget() {
    var widget = null;
    if (contextBar) {
        widget = contextBar.getWidgetByName("FolderActionsWidget");
    }
    return widget;
}
  
function handleBinderItemDataBound(sender, args) {
    var dataItem = args.get_dataItem();
    var width = dataItem.Width;
    var height = dataItem.Height;
  
    // resizing Images thumbnails
    var img = $(args.get_itemElement()).find(".sfImgTmb .sfSmallImgTmb img");
    if (img && img.length > 0) {
        resizeImage(img, width, height, 60);
    }
  
    // resizing Library thumbnails
    img = $(args.get_itemElement()).find(".sfImgTmb .sfSmallLibTmb img");
    if (img && img.length > 0) {
        img.load(function () {
            resizeImage($(this), this.offsetWidth, this.offsetHeight, 42);
        });
    }
  
    //hide video thumbnamil if snapshotUrl is not generated
    img = $(args.get_itemElement()).find(".sfVideoSelector img");
    if (img) {
        var snapshotUrl = dataItem.SnapshotUrl;
        if (!snapshotUrl || snapshotUrl == "") {
            img.hide();
        }
    }
  
    //tripple checking here explicitly because not all data items have the IsManageable property.
    if ((typeof (dataItem.IsManageable) != "undefined") && (dataItem.IsManageable != null) && (!dataItem.IsManageable)) {
        //------------------------------------ For libraries ------------------------------------
        if (dataItem.LibraryType) {
            //make the title and the album thumbnail unclickable
            $(args.get_itemElement()).find(".sfItemTitle").addClass("sfDisabled").removeClass("sf_binderCommand_viewItemsByParent").unbind("click").removeAttr("href");
            $(args.get_itemElement()).find(".sf_binderCommand_viewItemsByParent").removeClass("sf_binderCommand_viewItemsByParent").unbind("click").removeAttr("href");
  
            //hide the upload command
            $(args.get_itemElement()).find(".sf_binderCommand_upload").parent().hide();
  
            //hide the edit properties command
            $(args.get_itemElement()).find(".sf_binderCommand_edit").parent().hide();
  
            //hide the "change library" url command
            $(args.get_itemElement()).find(".sf_binderCommand_relocateLibrary").parent().hide();
  
            //hide the "move to another storage" command
            $(args.get_itemElement()).find(".sf_binderCommand_transferLibrary").parent().hide();
        }
  
            //------------------------------------ For individual media items ------------------------------------
        else {
            //hide the unpublish command
            $(args.get_itemElement()).find(".sf_binderCommand_unpublish").hide();
  
            //hide the publish command
            $(args.get_itemElement()).find(".sf_binderCommand_publish").hide();
  
            //hide the delete command
            $(args.get_itemElement()).find(".sf_binderCommand_delete").hide();
  
            //hide the edit properties command
            $(args.get_itemElement()).find("ul.actionsMenu li").children("a.sf_binderCommand_editMediaContentProperties").hide();
            $(args.get_itemElement()).find("a.sf_binderCommand_editMediaContentProperties").children("img").parent().remove("sf_binderCommand_editMediaContentProperties").unbind("click").removeAttr("href");
            $(args.get_itemElement()).find(".sf_binderCommand_editMediaContentProperties").removeClass("sf_binderCommand_editMediaContentProperties").unbind("click").removeAttr("href");
  
            //hide the revision history command
            $(args.get_itemElement()).find(".sf_binderCommand_historygrid").hide();
        }
  
    }
    //tripple checking here explicitly too because not sue all data items have the IsDeletable property.
    if ((typeof (dataItem.IsDeletable) != "undefined") && (dataItem.IsDeletable != null) && (!dataItem.IsDeletable)) {
        //hide the "delete item" command (and adjacent separator).
        $(args.get_itemElement()).find(".sfDeleteItm").parent().hide();
        $(args.get_itemElement()).find(".sfDeleteItm").parent().siblings(".sfSeparator").hide();
    }
  
    if (typeof (dataItem.IsFolder) != 'undefined' && dataItem.IsFolder) {
        jQuery(args.get_itemElement()).find(".sfTranslationCommands").hide();
        jQuery(args.get_itemElement()).find(".sf_NotForFolder").parent().hide();
    }
    else {
        jQuery(args.get_itemElement()).find(".sf_ForFolder").parent().hide();
    }
  
    // resizing Albums thumbnails
    img = $(args.get_itemElement()).find(".sfAlbumTmb img");
    if (img && img.length > 0) {
        var thumbnailUrl = dataItem.ThumbnailUrl;
        if (!thumbnailUrl || thumbnailUrl == "") {
            img.hide();
        }
        else {
            resizeImage(img, width, height, 80);
        }
    }
    var taskInfo = args.FindControl("taskInfo");
    if (taskInfo) {
        if (dataItem.TaskInfo && dataItem.TaskInfo.Description) {
  
            var description = args.FindControl("taskDescription");
            var status = dataItem.TaskInfo.Description + " " + dataItem.TaskInfo.Status.toLowerCase();
            description.innerHTML = status;
            var progressReport = args.FindControl("taskProgressReport");
            var progressBarEl = args.FindControl("taskProgressBar");
  
  
            if (dataItem.TaskInfo.FailureReport) {
                var errorPanel = args.FindControl("errorDetailsPanel");
                $(errorPanel).show();
                var errorDetails = args.FindControl("errorDetailsMessage");
                $(errorDetails).text(dataItem.TaskInfo.FailureReport);
                var errorLink = args.FindControl("errorDetailsLink");
                $(errorLink).click(function () { $(errorDetails).toggle(); return false; });
                updateProgressBar(progressBarEl, 0, "sfProgressStopped");
            }
  
  
            if (dataItem.TaskInfo.ProgressStatus >= 0) {
                progressReport.innerHTML = "(" + dataItem.TaskInfo.ProgressStatus + "% completed)";
                var colorCssClass = "sfProgressStarted";
                if (dataItem.TaskInfo.Status != "Started") {
                    colorCssClass = "sfProgressStopped";
                }
                updateProgressBar(progressBarEl, dataItem.TaskInfo.ProgressStatus, colorCssClass);
  
            }
            if (dataItem.TaskInfo.AvailableCommand) {
                commandButton = args.FindControl("taskCommand");
                $(commandButton).addClass("sf_binderCommand_" + dataItem.TaskInfo.AvailableCommand);
                $(commandButton).text(dataItem.TaskInfo.AvailableCommandTitle || "");
  
            }
        }
        else {
            $(taskInfo).hide();
  
        }
    }
}
  
function resizeImage(img, w, h, size) {
    if (h > size || w > size) {
        if (h == w) {
            img.attr("height", size);
            img.attr("width", size);
        }
        else if (h > w) {
            img.attr("width", size);
            // IE fix
            img.removeAttr("height");
        }
        else {
            img.attr("height", size);
            // IE fix
            img.removeAttr("width");
        }
    }
}
  
function getToolbarUploadWidget() {
    var widget = null;
    if (toolbar) {
        widget = toolbar.getWidgetByCommandName("upload");
    }
    return widget;
}
  
function getMoreActionsMenu() {
    var widget = null;
    if (toolbar) {
        widget = toolbar.getWidgetByName("MoreActionsWidget");
    }
    return widget;
}
  
function editTranslationHandler(sender, args) {
    args.set_cancel(true);
    var list = args.get_list();
    list.executeItemCommand("editMediaContentProperties", args.get_dataItem(), args.get_key(), { language: args.get_language(), languageMode: args.get_commandName() });
}
  
function updateProgressBar(parentElement, percents, colorCssClass) {
  
    if (!colorCssClass) colorCssClass = "sfProgressStarted";
  
    if (parentElement.hasChildNodes()) {
        while (parentElement.childNodes.length >= 1) {
            parentElement.removeChild(parentElement.firstChild);
        }
    }
    $(parentElement).removeClass("sfProgressStarted sfProgressStopped");
    $(parentElement).addClass(colorCssClass);
  
    var innerParentDiv = document.createElement('div');
    $(innerParentDiv).addClass("sfProgressBar");
  
    var innerDiv = document.createElement('div');
    innerDiv.setAttribute('style', 'width : ' + percents + '%;');
    $(innerDiv).addClass("sfProgressBarIn");
  
    innerParentDiv.appendChild(innerDiv);
    parentElement.appendChild(innerParentDiv);
}
  
function itemSelectHandler(sender, args) {
    if (moreActionsMenu) {
        var hasMediaItemsSelected = false;
        var binder = sender;
        for (var i = 0; i < binder.get_selectedItems().length; i++) {
            var dataItem = binder.get_selectedItems()[i];
            if (dataItem && !dataItem.IsFolder) {
                hasMediaItemsSelected = true;
                break;
            }
        }
  
        var publishItem = moreActionsMenu.get_menu().findItemByValue("groupPublish");
        var unpublishItem = moreActionsMenu.get_menu().findItemByValue("groupUnpublish");
        var bulkEditItem = moreActionsMenu.get_menu().findItemByValue("bulkEdit");
  
        if (hasMediaItemsSelected) {
            if (publishItem)
                publishItem.enable();
            if (unpublishItem)
                unpublishItem.enable();
            if (bulkEditItem)
                bulkEditItem.enable();
        }
        else {
            if (publishItem) {
                publishItem.disable();
                publishItem.set_disabledCssClass("sfDisabledLinkBtn");
            }
            if (unpublishItem) {
                unpublishItem.disable();
                unpublishItem.set_disabledCssClass("sfDisabledLinkBtn");
            }
            if (bulkEditItem) {
                bulkEditItem.disable();
                bulkEditItem.set_disabledCssClass("sfDisabledLinkBtn");
            }
        }
    }
}
  
function configureDisplayMode(displayMode) {
    if (displayMode) {
        var reorderWidget = toolbar.getWidgetByCommandName("reorder");
        var mainSection = sidebar.getSectionById("mainSection");
        var showAllMediaItemsSection = sidebar.getSectionById("showAllMediaItemsSection");
        var librariesPropertiesSection = contextBar.getSectionById("librariesPropertiesSection");
  
        if (reorderWidget) {
            jQuery(reorderWidget.get_element()).hide();
        }
        if (mainSection) {
            jQuery(mainSection).hide();
        }
        if (showAllMediaItemsSection) {
            jQuery(showAllMediaItemsSection).hide();
        }
        if (librariesPropertiesSection) {
            jQuery(librariesPropertiesSection).hide();
        }
  
        var clientLabelManager = masterGridView.get_clientLabelManager();
        var moduleTitle;
        if (displayMode == "allImages") {
            moduleTitle = clientLabelManager.getLabel("ImagesResources", "AllImages")
        }
        else if (displayMode == "allDocuments") {
            moduleTitle = clientLabelManager.getLabel("DocumentsResources", "AllDocumentsAndFiles")
        }
        else {
            moduleTitle = clientLabelManager.getLabel("VideosResources", "AllVideos")
        }
  
        jQuery("#" + masterGridView.get_titleID()).html(moduleTitle);
    }
    else {
        var showAllLibrariesSection = sidebar.getSectionById("showAllLibrariesSection");
        var categoryFilterSection = sidebar.getSectionById("categoryFilterSection");
        var tagFilterSection = sidebar.getSectionById("tagFilterSection");
        var dateFilterSection = sidebar.getSectionById("dateFilterSection");
        var moreFiltersSection = sidebar.getSectionById("moreFiltersSection");
  
        if (showAllLibrariesSection) {
            jQuery(showAllLibrariesSection).hide();
        }
        if (categoryFilterSection) {
            jQuery(categoryFilterSection).hide();
        }
        if (tagFilterSection) {
            jQuery(tagFilterSection).hide();
        }
        if (dateFilterSection) {
            jQuery(dateFilterSection).hide();
        }
        if (moreFiltersSection) {
            jQuery(moreFiltersSection).hide();
        }
    }
}
  
$(window).bind('resize', handleBinderDataBound);


I have marked the filter that we have applied to the java script.
3. Open your project in the browser and go to: Administration -> Settings -> Advance -> Content View -> Controls -> DocumentsBackend -> Views -> DocumentsBackendListView -> Scripts
4. Delete the default script
5. Create new script:
On Script Location type the name of the java script file that you have create in VS for example: ~/JavaScript1.js

On Name of the load method: OnMasterViewLoaded

6. Save the changes
7. Go to Administration -> Settings -> Advance -> Content View -> Controls -> DocumentsBackend -> Views -> DocumentsBackendListView -> Sidebar -> Sections -> FilterOptions -> Items and select AllDocuments
8. Go to Button CSS class and remove the value of the field
9. Save the changes
10. Go to Administration -> Settings -> Advance -> Content View -> Controls -> DocumentsBackend -> Views -> DocumentsBackendListView -> Sidebar -> Sections -> FilterOptions -> Items and select MyDocuments
11. Go to Button CSS class and add this value: sfSel
12. Save the changes

Setting this value for Button CSS class in MyDocuments will make My Items filter visibly selected.

13. Restart you application.

 
My items will be the default filter when the Filter you items link is selected.


Leave a comment