Search This Blog

Sunday, September 22, 2013

FilterName for multiple columns for searching a Custom List

2. Add Content Editor Web part on it.
3. Add below script in Source Editor - See more at: http://www.go4sharepoint.com/Forum/render-failed-error-list-view-2203.aspx#sthash.1NGcmTtM.dpuf
2. Add Content Editor Web part on it.
3. Add below script in Source Editor - See more at: http://www.go4sharepoint.com/Forum/render-failed-error-list-view-2203.aspx#sthash.1NGcmTtM.dpuf


1. Add Content Editor Web part on it. (insert Custom List)
2. Add Script Editor and Paste below code

3. Add below script in Source Editor - See more at: http://www.go4sharepoint.com/Forum/render-failed-error-list-view-2203.aspx#sthash.1NGcmTtM.dpuf
<html>
<head>
  <script type="text/javascript">
      function RedirectUrl() {
        
          var tbCity = document.getElementById("tbSearchCity").value;
          var tbAdress = document.getElementById("tbSearchAddress").value;
          var tbstate = document.getElementById("tbState").value;
          var tbZIPCode = document.getElementById("tbZIPCode").value;
          var Query = "";
          if (tbCity != null && tbCity != "") {

              Query = "?FilterName=City&FilterMultiValue=*" + tbCity + "*";
          }
          if (tbAdress != null && tbAdress != "") {
              if (Query == "") {
                  Query = "?FilterName=Address&FilterMultiValue=*" + tbAdress + "*";
              }
              else {
                  Query = Query + "&FilterName=Address&FilterMultiValue=*" + tbAdress + "*";
              }
          }
          if (tbstate != null && tbstate != "") {
              if (Query == "") {
                  Query = "?FilterName=State&FilterMultiValue=*" + tbstate + "*";
              }
              else {
                  Query = Query + "&FilterName=State&FilterMultiValue=*" + tbstate + "*";
              }
          }
          if (tbZIPCode != null && tbZIPCode != "") {
              if (Query == "") {
                  Query = "?FilterName=Zip_x0020_Code&FilterMultiValue=*" + tbZIPCode + "*";
              }
              else {
                  Query = Query + "&FilterName=Zip_x0020_Code&FilterMultiValue=*" + tbZIPCode + "*";
              }
          }
         
          window.location.href = Query;
     
      }
</script>

</head>
<body>
    <table>
        <tr>
            <td>
                City
            </td>
            <td>
                <input type="text" id="tbSearchCity" />
            </td>
        </tr>
        <tr>
            <td>
                Address
            </td>
            <td>
                <input type="text" id="tbSearchAddress" />
            </td>
        </tr>
        <tr>
            <td>
                State
            </td>
            <td>
                <input type="text" id="tbState" />
            </td>
        </tr>
        <tr>
            <td>
                ZIP code
            </td>
            <td>
                <input type="text" id="tbZIPCode" />
            </td>
        </tr>
         <tr>
            <td>
                &nbsp;
            </td>
            <td>
               <input type="button" id="btnSearch" value="search" onclick="return RedirectUrl();" />  &nbsp;<input type="button" id="btnClear" value="Clear" onclick="window.location.href = '/sites/devloop/Pages/Location-Search.aspx'" />
            </td>
        </tr>
    </table>

</body>
</html>


Thursday, September 19, 2013

Update Custom Breadcrumb- Sharepoint 2013

<%-- breadcrumb --%>
<div class="loop-breadcrumb">
<div id='javascript-breadcrumb' class='selected'></div>
</div>
 <%-- /breadcrumb --%>
<script>
    if (document.addEventListener) {
        document.addEventListener('DOMContentLoaded', function () {
            EnsureScriptFunc('sp.js', 'SP.ClientContext', JavascriptBreadcrumb);
        }, false);
    } else {
        window.setTimeout(function () {
            EnsureScriptFunc('sp.js', 'SP.ClientContext', JavascriptBreadcrumb);
        }, 0);
    }

    function JavascriptBreadcrumb() {

        if (_spPageContextInfo.pageListId !== null && _spPageContextInfo.pageListId !== undefined)

        // Retrieve the breadcrumb element
            this.elm = document.getElementById('javascript-breadcrumb');

        if (window.location.pathname.indexOf("Lists") != -1) {
            var path = window.location.pathname;
            //document.getElementById('javascript-breadcrumbx').innerHTML = window.location.href;
            var breadcrumbpth = "";
            var bredname = "";
            var separated = path.split("/");
            var titl = document.title.split('-');

            if (titl[1] != undefined) {
                titl = " > " + document.title.split('-')[1];
            }
            else {
                titl = " > " + document.title;
            }

            for (var i = 0, length = separated.length - 1; i < length; i++) {

                if (i > 2) {
                    bredname += "/" + separated[i];

                    var webAbsoluteUrl = _spPageContextInfo.webAbsoluteUrl;
                    var sppath = separated[i].replace(/-/g, " ");
                    breadcrumbpth += " > " + "<a href=" + webAbsoluteUrl + "" + bredname + ">" + sppath.replace(/%20/g, " ") + "</a>";
                }
                if (length == 3) {
                    breadcrumbpth = " > " + "<span style='font-weight:bold;'>" + document.title.replace("%20", " ") + "</span>";
                    titl = "";

                }
            }

            // Add the current site link to the breadcrumb
            var breadcrumburl = breadcrumbpth;
            breadcrumburl = breadcrumburl.toLowerCase().replace(/\b[a-z]/g, function (letter) {
                return letter.toUpperCase();
            });

            this.breadcrumb = "<a href='" + _spPageContextInfo.webAbsoluteUrl + "' >" + _spPageContextInfo.webTitle + "</a><span style='font-style:normal;'>" + breadcrumburl + "</span><span style='font-weight:bold;'>" + titl + "</span>";
            this.elm.innerHTML = this.breadcrumb;

        }

        if (_spPageContextInfo.pageListId !== null && _spPageContextInfo.pageListId !== undefined) {
            if (window.location.pathname.indexOf(".aspx") == -1) {

                var path = window.location.pathname;

                var breadcrumbpth = "";
                var bredname = "";
                var separated = path.split("/");
                var titl = document.title.split('-');
                var FormTitle = "";
                if (titl[1] != undefined) {
                    if (titl.length == 2) {
                        titl = " > " + "<span style='font-weight:bold;'>" + document.title.split('-')[1] + "</span>";

                    }
                    else {
                        for (var i = 0, length = titl.length - 1; i < length; i++) {

                            FormTitle += " " + titl[i];
                        }

                        titl = " > " + "<span style='font-weight:bold;'>" + FormTitle + "</span>";
                    }
                }

                else {
                    titl = " > " + "<span style='font-weight:bold;'>" + document.title + "</span>";
                }

                for (var i = 0, length = separated.length - 1; i < length; i++) {

                    if (i > 2) {
                        if (separated[i] == "gbt" || separated[i] == "Gbt") {
                            separated[i] = separated[i].toUpperCase();
                        }

                        bredname += "/" + separated[i];
                        var webAbsoluteUrl = _spPageContextInfo.webAbsoluteUrl;
                        breadcrumbpth += " > " + "<a href=" + webAbsoluteUrl + "" + bredname + ">" + separated[i].replace(/-/g, " ") + "</a>";
                    }
                    if (length == 3) {
                        breadcrumbpth = " > " + "<span style='font-weight:bold;'>" + document.title + "</span>";
                        titl = "";

                    }
                }

                // Add the current site link to the breadcrumb
                var breadcrumburl = breadcrumbpth;

                breadcrumburl = breadcrumburl.replace(/\b[a-z]/g, function (letter) {
                    return letter.toUpperCase();
                });

                this.breadcrumb = "<a href='" + _spPageContextInfo.webAbsoluteUrl + "' >" + _spPageContextInfo.webTitle + "</a><span style='font-style:normal;'>" + breadcrumburl + "</span><span style='font-weight:normal;'>" + titl + "</span>";
                this.elm.innerHTML = this.breadcrumb;
            }
        }
        // Retrieve the parent web of the current site
        var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
        this.web = clientContext.get_web();
        this.parentweb = this.web.get_parentWeb();

        clientContext.load(this.parentweb);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySuccess), Function.createDelegate(this, this.onCreationFail));
    }

    function onQuerySuccess() {
        try {
            // Check if the current web has a title, if undefined, the top site has already been reached
            if (this.parentweb.get_title() !== undefined) {
                // Add the parent site to the breadcrumb
                this.breadcrumb = "<a href='" + this.parentweb.get_serverRelativeUrl() + "' style='color:#fff'>" + this.parentweb.get_title() + "</a>" + " > " + this.breadcrumb;
                this.elm.innerHTML = this.breadcrumb;
                // Retrieve the parent its parent site
                var clientContext = new SP.ClientContext(this.parentweb.get_serverRelativeUrl());
                this.web = clientContext.get_web();
                this.parentweb = this.web.get_parentWeb();

                clientContext.load(this.parentweb);
                clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySuccess), Function.createDelegate(this, this.onCreationFail));
            }
        }
        catch (e) { }
    }

    function onCreationFail() { }

</script>

Kendo UI Stock Value Display on Home Page

<html>
<head>
    <title></title>
    <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.rtl.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.default.min.css"
        rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.dataviz.min.css"
        rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://cdn.kendostatic.com/2012.3.1315/js/kendo.all.min.js"></script>
</head>
<body>
    <div id="Stock">
    </div>
    <table>
        <tr>
            <td colspan="3">
                <h2>
                    G.F. Corporation (GFC)
                </h2>
            </td>
        </tr>
        <tr>
            <td>
                <h2>
                    <span id="spnAsk"></span>
                </h2>
            </td>
            <td>
                <div id="divMark">
                </div>
            </td>
            <td>
                <h3>
                    <span id="spnOpen"></span>( <span id="SpnMinus"></span>)</h3>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        var apiStockUrl = 'http://testsites.cloudapp.net/api/Stock?symbol=vfc';

        $(document).ready(function () {
            var auto_div_refresh = setInterval(function () {

                var FixdValue = "0";

                $.getJSON(apiStockUrl)
                .done(function (data) {
                    // alert(data);
                    $.each(data, function (key, item) {
                        //alert(item);                  
                        if (key == 'Ask') {

                            //var oAsk = item;

                            document.getElementById('spnAsk').innerHTML = item;

                        }
                        if (key == 'Open') {

                            //var oOpen = item;
                            var Opnalue = document.getElementById('spnOpen').innerHTML = item;
                            var AskValue = document.getElementById('spnAsk').innerHTML;
                            Opnalue = 100;
                            AskValue = 70;
                            FixdValue = AskValue - Opnalue;
                            document.getElementById('SpnMinus').innerHTML = FixdValue.toFixed(2);
                        }
                        document.getElementById("divMark").innerHTML = "";
                        if (FixdValue > 0) {
                            document.getElementById("divMark").innerHTML = ">";

                        }
                        else if (FixdValue == 0) {
                            document.getElementById("divMark").innerHTML = "=";

                        }
                        else {
                            document.getElementById("divMark").innerHTML = "<";


                        }

                    });
                });
            }, 6000);
        });

    </script>
</body>

</html>

Client object Model: Content Editor Sharepoint list and display on a page

1) Add content editor webpart on page.

2) Add the below content in the content editor webpart: Here I want to create a list (with ul, li tags) having an anchor tag (text fetched from "title" column) which points to a URL fetched from a column of the list. Also the css class to be applied on each <li> tag is fetched from a custom column.

<div class="testcss">
    <ul>
        <li><a href="#my-quick-links">Quick links</a></li>
    </ul>
    <div id="my-quick-links">
    </div>
</div>
<script type="text/javascript">

    //We need to run our function only after sp.js file loads
    ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
    function ViewItem() {
        var context = new SP.ClientContext.get_current();
        var web = context.get_web();
        var list = web.get_lists().getByTitle('QuickLinksHome');

        //It will fetch all the items from the list
        var myquery = new SP.CamlQuery.createAllItemsQuery();
        myItems = list.getItems(myquery);
        context.load(myItems);

        //If the items load correctly then success function will be called
        context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
    }

    function success() {
        var text = "";
        var LinkURL = "";
        var TextURL = "";
        var cssClass = "";
        var Active = "";
        var ListEnumerator = this.myItems.getEnumerator();
        text = '<ul>';
        while (ListEnumerator.moveNext()) {
            //Will get the current row from the SP List
            var currentItem = ListEnumerator.get_current();
            Active = currentItem.get_item('IsActive');
            if (Active == "Yes") {
                //Will get the "Url" column from the current row
                LinkURL = currentItem.get_item('Link');

                TextURL = currentItem.get_item('Title');

                //String is formed with links pointing to URLs with css applied
                text = text + '<li class="loop-quick-links">';
                text = text + ('<a href="' + LinkURL + '">' + TextURL + '</a></li>');
            }
        }
        text = text + '</ul>';

        //Getting the empty div tag
        fieldNameElement = document.getElementById('loop-quick-links');

        //Assign the string formed to the div element's innerHTMl to display on page
        fieldNameElement.innerHTML = text;
    }

    function failed(sender, args) {
        alert("failed. Message:" + args.get_message());
    }

</script>