Tuesday, December 3, 2013

Disable lookup value links

Disable lookup value links from Display and AllItems page using Jquery

Step 1: Add HTML Webpart on Lists  Display or AllItems form page.





Step 2: Add Following code into Source Editor of HTML Form Webpart.

<script type="text/javascript" src="../../Shared%20Documents/jquery-1.7.2.js"></script>

<script type="text/javascript" src="../../Shared%20Documents/jquery-1.7.2.min.js"></script>

<script type="text/javascript">
$(function () {

    RemoveLookupLinks();
 });


 function RemoveLookupLinks() {
    $('a[href*="RootFolder=*"]').each(function (index) {
        var link = $(this);
        $(this).after("<span>" + link.text() + "</span>");
        $(this).remove();
    });

//below code used if you selected multiple lookup values in the column.
    var vCity = $('h3:contains("City")').closest('td').next('td').find('a').text();

    if (vCity!= undefined || vCity!= "") {
        $('h3:contains("City")').closest('td').next('td').find('a').after("<span>" + vCity + "</span>");
        $('h3:contains("City")').closest('td').next('td').find('a').remove();
    }
}

</script>
Step 3: Save the Webpart and open Display form of list. The Lookup links disabled from display form.

 



Hide Created By and Modified By Bottom information from Display form or Edit form of SharePoint List using Jquery.


Step 1: Add HTML Webpart on Lists  Display or Edit form page. (Dispform.aspx)



Step 2: Add Following code into Source Editor of HTML Form Webpart.


<script type="text/javascript" src="../../Shared%20Documents/jquery-1.7.2.js"></script>

<script type="text/javascript" src="../../Shared%20Documents/jquery-1.7.2.min.js"></script>

<script type="text/javascript">
$(function () {

     HideBottomInformation();
 });


 function HideBottomInformation() {
    $('#onetidinfoblockV').css("display", "none");
    $('#onetidinfoblock1').css("display", "none");
    $('#onetidinfoblock2').css("display", "none");
    $('#onetidinfoblockV').hide();
    $('#onetidinfoblock1').hide();
    $('#onetidinfoblock2').hide();
}

</script>

Step 3: Save the Webpart and open Display form of list. The Bottom information hidden from display form.




Search SharePoint List Items using OOB


SharePoint List Dynamic Search using Jquery.

Step 1: Add HTML Webpart on List view page. (AllItems.aspx)




Step 2: Add Following code into Source Editor of HTML Form Webpart.
<div id="mainDiv" class="divbackgroundColor">
    <table>
        <tr>
            <td class='Filter' width='90px' style="color:#1b3f97;font-weight:bold;">Search:</td><td class='Filter' width='125px'> <input type="Text" id="filterInput" ></td>
        </tr>
    </table>
</div>

<br></br>

<script type="text/javascript" src="../../Scripts%20Files/jquery-1.7.2.js"></script>
<script type="text/javascript" src="../../Scripts%20Files/jquery-1.7.2.min.js"></script>
<script type="text/javascript">

$(function () {

    $('#filterInput').keyup(function () {
        DynamicFilter($('#filterInput').val());
    });
 });


 function DynamicFilter(text) {

    $('table[class="ms-listviewtable"]').find('tr').each(function () {
        if ($(this).attr("class") != "ms-viewheadertr ms-vhltr") {
            source = stripHTML($(this).html());

            if ((source.toLowerCase()).indexOf(text.toLowerCase()) < 0) {
                $(this).hide();
            } else {
                $(this).show();
            }
        }
    });
}

function stripHTML(field) {
    return field.replace(/<([^>]+)>/g, '');
}

</script>



Step 3: The Text box appear on the top of list view.



Enter the search Text into Search Textbox. The Entered text searching into list view webpart.




Advantages:
1.       This is OOB functionality, Server access not needed.
2.       Fast and simple to implement.

Limitations:
1.       This functionality does not works for paging of list records.


SharePoint List Export To Excel

SharePoint List Custom Export to Excel functionality using Jquery.

Step 1: Add HTML Webpart on List view page. (AllItems.aspx)



Step 2: Add Following code into Source Editor of HTML Form Webpart.
<A id="ExportToExcel" class="ms-cui-ctl-medium " onclick="ExportToExcel('{D1E64C5F-EF3D-4E0D-856E-FBEDB6CE2E4E}-{14184870-CBAE-4950-8426-E4F08EE21E9A}');" href="javascript:;" mscui:controltype="Button">
<SPAN class="ms-cui-ctl-iconContainer" unselectable="on">
<SPAN class="ms-cui-img-16by16 ms-cui-img-cont-float" unselectable="on">
<IMG alt="" src="/_layouts/images/ExportToExcel16x16.png" unselectable="on">
</SPAN></SPAN><SPAN class="ms-cui-ctl-mediumlabel" unselectable="on">Export view to excel</SPAN></A>
<br></br>

<script type="text/javascript" src="../../Scripts%20Files/jquery-1.7.2.js"></script>
<script type="text/javascript" src="../../Scripts%20Files/jquery-1.7.2.min.js"></script>
<script type="text/javascript">

function ExportToExcel(strTableID) {
    if ($.browser.msie) {

        var detailsTable = document.getElementById(strTableID);
        try {
            var objExcel = new ActiveXObject("Excel.Application");
            if (objExcel == undefined) {
                alert("Please go to the 'Tools >> Internet Options >> Security >> Custom Level' and set: \n Automatic prompting for ActiveX control--> Enable \n Download unsigned ActiveX control --> Prompt \n Run ActiveX control and plug-ins  --> Enable");
                return false;
            }
        }
        catch (err) {
            alert("Please go to the browser setting 'Tools >> Internet Options >> Security >> Custom Level' and set: \n Automatic prompting for ActiveX control--> Enable \n Download unsigned ActiveX control --> Prompt \n Run ActiveX control and plug-ins  --> Enable \n Initialize and script ActiveX controls not marked as safe for scripting --> Prompt");
            return false;
        }
        var objWorkBook = objExcel.Workbooks.Add;
        var objWorkSheet = objWorkBook.Worksheets(1);

        for (var intRowIndex = 0; intRowIndex < detailsTable.rows.length; intRowIndex++) {
            for (var intColumnIndex = 0; intColumnIndex < detailsTable.rows(intRowIndex).cells.length; intColumnIndex++) {
                objWorkSheet.Cells(intRowIndex + 1, intColumnIndex + 1) = detailsTable.rows(intRowIndex).cells(intColumnIndex).innerText;
            }
        }
        objExcel.Visible = true;
        objExcel.UserControl = true;
    }
    else {
        alert("Use Internet Explorer browser for Export to excel");
    }
}

</script>

In the above code “{D1E64C5F-EF3D-4E0D-856E-FBEDB6CE2E4E}-{14184870-CBAE-4950-8426-E4F08EE21E9A}” is the ID of Webpart table. Following way you can get this ID.



Step 3: Click on “Export View To Excel” icon.


The following pop-up Alert open, click on Yes button.


Step 4: The List exported to excel.




Advantages:
1.       This is OOB functionality, Server access not needed.
2.       Fast and simple to implement.

Limitations:
1.       This functionality works only IE browser.
2.       Next Page of List records does not Exporting to Excel.
3.       IE browser’s setting configuration needed. Need to Activate ActiveX control from IE browser as per mentioned in Code.