Replace the New Item button on a SharePoint 2010 list with jQuery

I have a SharePoint 2010 Business Data Catalog (BDC) pointing to our MS CRM 20111 back end. This is a good way to show paged views of the database. But at the top, there is still a “New Item” button. This does not make much sense for a BDC (or External list) without update queries. I wanted a workaround. I wanted to “hijack” this button – Make it do what I want. This is the jQuery code to do that!
Basically I am hiding the existing button, and replacing it with what I want.

    $("#RibbonContainer").ready(function () {
        var imageRow = '<span class="ms-cui-ctl-large" onclick=\"window.location=\'/Destination/YouWant/NewForm.aspx?source=/Lists/BDCList/Default.aspx?InitialTabId=Ribbon.ListItem\'; \") > \
            <a class="ms-cui-ctl-a1 "  href="javascript:;" > \
            <span class="ms-cui-ctl-a1Internal" unselectable="on"> \
            <span class=" ms-cui-img-32by32 ms-cui-img-cont-float" unselectable="on"> \
            <img class="" style="left: -64px; top: -320px;" src="/_layouts/1033/images/formatmap32x32.png" /> \
            </span> \
            </span> \
            </a> \
            <a class="ms-cui-ctl-a2"><span class="ms-cui-ctl-largelabel"> New <br/> Item </span></a> \
            </span>'
        $("#s4-ribboncont .ms-cui-ctl-large:contains('New Item')").hide()
        $("#s4-ribboncont .ms-cui-ctl-large:contains('New Item')").before(imageRow)
    }); 

,

2 Responses to Replace the New Item button on a SharePoint 2010 list with jQuery

  1. Mike W July 16, 2015 at 4:32 pm #

    I attempted to get this to work, but I’m having problems understanding

    1. The version of JQuery you used and what do I change to get this to work for an Edit Form button.

    Thanks for the help.

    Mike

  2. Mike W July 16, 2015 at 4:33 pm #

    I attempted to get this to work, but I’m having problems understanding

    1. The version of JQuery you used and what do I change to get this to work for an Edit Form button.

    Thanks for the help.

    Mike

    Your comment is awaiting moderation