none
SharePoint 2013 : Setting default to 'One Year Ago' in Modified date refiner RRS feed

  • Question

  • Hi,

    I wanted to set the default to 'One Year Ago' in Modified date refiner, I want that when user searches modified date refiner should show only results not older than one year, and when user wants to explicitly see the old result then he/she can select the 'All" option in the bar chart refiner.

     

    I am able to do this but by calling AjaxControlToolkit.SliderRefinementControl.FindAndSetSliderHandlesAndValuesToRange(ctx.RefinementControl.containerId, 1, 5, this); 

    in 'Filter_SliderBarGraph.html' but the problem is that 'Filter_SliderBarGraph.html' is gatting called only once, initially.

    After that if we change the search term and press search button in search box it is again showing 'All' option in the Modified date filter.

    I observed that though we have selected 'Filter_SliderBarGraph.html' this refiner template for 'Date Modified' refiner but it is not getting called always unlikely Filter_Default gets called always.

    Please help me to understand the issue or  the solution to my requirement.

    BR,

    Prasad Pathak

    Sunday, April 16, 2017 10:22 AM

All replies

  • Hi,

    Thank you for your post.

    This is a quick note to let you know that we are performing research on this issue.

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, April 21, 2017 6:44 AM
  • Hi,

    I tried some approaches to update the OOTB slider control behavior but without luck.

    You could try to create a custom Range Refiner Control for your purpose, here is one thread for your reference.

    https://www.eliostruyf.com/part-7-working-ranges-search-refiner-control/

    <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
    <head>
        <title>Range Filter</title>
        <!--[if gte mso 9]>
        <xml>
            <mso:CustomDocumentProperties>
                <mso:CompatibleManagedProperties msdt:dt="string"></mso:CompatibleManagedProperties>
                <mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
                <mso:CompatibleSearchDataTypes msdt:dt="string">;#DateTime;#Integer;#Decimal;#</mso:CompatibleSearchDataTypes>
                <mso:MasterPageDescription msdt:dt="string"></mso:MasterPageDescription>
                <mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106604</mso:ContentTypeId>
                <mso:TargetControlType msdt:dt="string">;#Refinement;#</mso:TargetControlType>
                <mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
        </xml>
        <![endif]-->
        <script>
         
        </script>
    </head>
    <body>
        <div id="RangeFilter">
            <!--#_          
            var listData = ctx.ListData;
            var hasControl = true;
            // Check if the current Refinement Control exists
            if ($isNull(ctx.RefinementControl) || $isNull(ctx.ClientControl)) hasControl = false;
            
            if (hasControl) {
                // Check if listdata contains data
                if(!$isNull(listData) && !$isEmptyArray(listData)) {
                	// Element IDs
    		        var controlID = ctx.RefinementControl.containerId + "_" + ctx.RefinementControl.propertyName;
    		        var fromInput = controlID + "_from";
    		        var toInput = controlID + "_to";
    		        var refineLink = controlID + "_refine";
    		        var clearLink = controlID + "_clear";
                    // Show the refinement title
                    var isExpanded = Srch.Refinement.getExpanded(ctx.RefinementControl.propertyName);
                    var iconClass = (isExpanded == "true"? "ms-ref-uparrow" : "ms-ref-downarrow");
                    var refinerCatTitle = Srch.Refinement.getRefinementTitle(ctx.RefinementControl);
                    // Display style > needed to hide the refinement list when collapsed
                    var displayStyle = (isExpanded == "true"? "" : "none");
                    // Set input form values
                    var from = "";
                    var to = "";
                    var currentRefinementCategory = ctx.ClientControl.getCurrentRefinementCategory(ctx.RefinementControl.propertyName);
                    // Check if the current control refinement is in use
                    if(!Srch.U.n(currentRefinementCategory) && currentRefinementCategory.get_tokenCount() == 1) {
                        // Parse the current filter token to find the current range condition
                        var matchResults = Srch.U.parseTypedRangeToken(currentRefinementCategory.t[0], null);
                        // check for a range token match with corresponding min and max
                        if (matchResults != null && matchResults.length > 2) {
                            var from = matchResults[1] === "min" ? "" : matchResults[1];
                            var to = matchResults[2] === "max" ? "" : matchResults[2];
                        }
                    }
    _#-->
                    <div id='Container'>
                        _#= Srch.U.collapsibleRefinerTitle(ctx.RefinementControl.propertyName, ctx.ClientControl.get_id(), refinerCatTitle, iconClass) =#_
    
                        <div class='ms-ref-unselSec' style='display:_#= $htmlEncode(displayStyle) =#_'>
                            <label for='_#= fromInput =#_'>From</label>
                            <input type='text' id='_#= fromInput =#_' name='from' value='_#= from =#_' />
                            <label for='_#= toInput =#_'>To</label>
                            <input type='text' id='_#= toInput =#_' name='to' value='_#= to =#_' />
                            <a href='javascript:{}' id="_#= refineLink =#_">Refine</a>
                            <a href='javascript:{}' id="_#= clearLink =#_">Clear</a>
                        </div>
                    </div>
    <!--#_
                    ctx.OnPostRender = [];
                    ctx.OnPostRender.push(function () {
                        // Retrieve the two hyperlinks 
                        var refineLinkElm = document.getElementById(refineLink);
                        var clearLinkElm = document.getElementById(clearLink);
                        // Create an onclick event for the refinement link
                        refineLinkElm.onclick = function () {
                            // Retrieve the two input fields
                            var fromInputElm = document.getElementById(fromInput);
                            var toInputElm = document.getElementById(toInput);
                            // Check if the two input fields contains a value, otherwise nothing needs to be done
                            if (fromInputElm.value.trim() !== "" || toInputElm.value.trim() !== "") {
                                // Retrieve the input values
                                var fromValue = fromInputElm.value.trim() === "" ? "min" : fromInputElm.value.trim();
                                var toValue = toInputElm.value.trim() === "" ? "max" : toInputElm.value.trim();
                                
                                // Refinement value
                                if (ctx.ListData[0].filterTokenType === "decimal") {
                                    fromValue = fromValue === "min" ? fromValue : 'decimal(' + fromValue + ')';
                                    toValue = toValue === "max" ? toValue : 'decimal(' + toValue + ')';
                                }
                                // Create the refinement JSON value string
                                var refinement = '{"'+ ctx.RefinementControl.propertyName +'":["range('+fromValue+','+toValue+')"]}';
                                $getClientControl(this).updateRefinersJSON(refinement);
                            }
                        };
                        
                        // Create a onclick event to remove the refinement
                        clearLinkElm.onclick = function () {
                            // NULL Refinement value to remove the refinement
                            var refinement = '{"'+ ctx.RefinementControl.propertyName +'":null}';
                            $getClientControl(this).updateRefinersJSON(refinement);
                        };
                    });
                }
            }
    _#-->
        </div>
    </body>
    </html>

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, April 25, 2017 7:34 AM
  • Hi Prasad,

    I have a similar requirement. Kindly let me know if you have found a solution for this requirement.

    Thanks

    Nez

    Thursday, July 13, 2017 6:28 AM
  • Hi Nez,

    I still not found the working solution, please share if anything found working for you.

    Thanks,

    Prasad

    Tuesday, August 1, 2017 4:31 AM