ads

Monday, December 26, 2022

SharePoint custom html form input autocomplete users

SharePoint expose a lot of API. SP REST API reference and samples

The more you know them it's will be easy develop a lot of features

So in our tutorial we will be use   this api "/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";

to make ajax call and retrieve list of users by param input

1.       first we added a reference to jQuery and jQuery UI library in our page

2.       our html form will be look like this

<div id="my-custom-form">

<input type="text" id="emplyeeName" />

</div>

 

3.       JS – our script looks like this

<script>

// user picker auto complete rest api

function searchUsers(request, response) {

 

    var qURL = _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser";

    var principalType = this.element[0].getAttribute('principalType');

    $.ajax({

        'url': qURL,

        'method': 'POST',

        'data': JSON.stringify({

            'queryParams': {

                '__metadata': {

                    'type': 'SP.UI.ApplicationPages.ClientPeoplePickerQueryParameters'

                },

                'AllowEmailAddresses': true,

                'AllowMultipleEntities': false,

                'AllUrlZones': false,

                'MaximumEntitySuggestions': 20,

                'PrincipalSource': 15,

                'PrincipalType': 15,

                'QueryString': request.term,

                'Required': false

 

 

 

            }

        }),

        'headers': {

            'accept': 'application/json;odata=verbose',

            'content-type': 'application/json;odata=verbose',

            'X-RequestDigest': $("#__REQUESTDIGEST").val()

        },

        'success': function (data) {

            var d = data;

            var results = JSON.parse(data.d.ClientPeoplePickerSearchUser);

            if (results.length > 0) {

                response($.map(results, function (item) {

                    //  return {label:item.DisplayText,value:item.DisplayText} 

                    return {

                        label: item.DisplayText,

                        value: item.Key.replace("i:0#.w|domain\\", "")

                    }

                }));

            }

        },

        'error': function (err) {

            if (err.responseJSON.error.code = "-2130575252, Microsoft.SharePoint.SPException")

                RefreshRequestDigist();

            else

                alert(JSON.stringify(err));

        }

    });

}

$(document).ready(function(){

    $("#emplyeeName").autocomplete({

        source: searchUsers,

        minLength: 2,

        select: function (event, ui) {

            var label = ui.item.label;

            var value = ui.item.value;

            $("#emplyeeName").val(ui.item.label);

 

            return false;

        }

    });

});

</script>

Sunday, December 25, 2022

SharePoint List Rendering with VUE.JS Ajax call

When we using in client side developing is not matter what version of SharePoint it will work in all version of SharePoint.

Steps:

1.       Create SP list with Name "Test"

2.       Add some data to list

3.       For the example I have only title column

 

Now after creating the list we will write some code

1.       Create a folder in your workspace with name ex "vue-demo-sp-list"

2.       Inside the folder create a html file "index.html"

3.       Open the file with editor (vs-code,notpad++)

4.       Copy the code below

 

<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>

<div id="app">

                <table class="table">

                                <thead>

                                                <tr>

                                                                <th>Title</th>

                                                </tr>

                                </thead>

                                <tbody>

                                                <tr v-for="item in items">

                                                                <td>{{item.title}}

                                                                </td>

                                                </tr>

                                </tbody>

                </table>

</div>

 

<script>

const app = new Vue({

    el: '#app',

                data() {

                                return {

                                                items:[]

                                                }

                                },

                created: function () {

                                    this.getTestList();                                       

                                },

                methods: {

                                getTestList:function() {

                                 

                                  var that = this;

 

            var endPointUrl = _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbyTitle('Test')/items";

            var headers = {

                "accept": "application/json;odata=verbose"

            };

            $.ajax({

                url: endPointUrl,

                type: "GET",

                headers: headers,

                success: function (data, status, xhr) {

                    that.items = data.d.results;

                    //alert('Success');

                },

                error: function (xhr, status, error) {

 

                   console.log("error",xhr);

 

                }

            });

        },

                                }

                });

</script>

 

5.       upload to sharepoint assets folder create folder for the project

6.       add content editor webpart in some page and put the link to the file "index.html""

DEMO

Title
{{item.title}}

Monday, December 21, 2015

how to show oracle table in SharePoint page (gridView)


1. Create custom .aspx page in sharepoint
2. Edit page with sharepoint designer
3.Grab a  SqlDataSource  from the insert--> ASP.NET -->Data ToolBox and set up your connection string like below: 

<asp:SqlDataSource runat="server" ID="myOracleDBSourceProviderName="System.Data.OracleClient" ConnectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[host name])(PORT=[port number]))(CONNECT_DATA=(SERVICE_NAME=[service name])));User ID=[username];Password=[Password];Unicode=True" SelectCommand="SELECT * FROM [view name] ">
</asp:SqlDataSource>

4. Grab a GridView from the insert--> ASP.NET -->Data ToolBox and then Set AutoGenerateColumns to False. 
- Add BoundField Columns in GridView and set the DataField and the HeaderText accordingly. See below:

<asp:GridView  runat="server" id="myOracleGridView" AutoGenerateColumns="False" DataSourceID="myOracleDBSourceAllowPaging="True">
<EmptyDataTemplate>No Records Found !</EmptyDataTemplate>

<Columns>
<asp:boundfield  DataField="column 1HeaderText="column 1SortExpression="column 1">
</asp:boundfield>
<asp:boundfield  DataField="column 2HeaderText="column 2SortExpression="column 2">
</asp:boundfield>
</asp:GridView>

5. Compile and run your page to see the output
Column 1 Column 2
Eve Jackson
John Adisu





Wednesday, July 9, 2014

Hide/Exclude first row in repeating table

when we use repeating table some time we didn't want to show first entire row
so how we hide this?

Steps:

  a.     On the ribbon go to Data --> on Form Data group select Default Values



b. on dialog box just remove the check box

c. Click Preview

Result




Countdown clock Sample with date diff

//html
<h1 >Countdown clock Sample</h1>
<h1 id="demo" ></h1>

//java script
<script>
//declare variables
var days,hours ,minutes ,seconds=60;

//set future date
var d1=new Date(2015,08,30); // Sep,31 2011
//set Time future
d1.setHours(23) ;//Set the hour (0-23) 
d1.setMinutes(59) ;//Set the minutes (0-59) 
d1.setSeconds(59) ;//Set the seconds (0-59) 


var d2=new Date(); // now

//calc diff date
var diff=d2-d1,sign=diff<0?-1:1,milliseconds,seconds,minutes,hours,days;
diff/=sign; // or diff=Math.abs(diff);
diff=(diff-(milliseconds=diff%1000))/1000;
diff=(diff-(seconds=diff%60))/60;
diff=(diff-(minutes=diff%60))/60;
days=(diff-(hours=diff%24))/24;

//inerval  each second
var timer=setInterval(function(){myCounter()},1000);
//interval function  
function myCounter()
{
     seconds--;
     if(seconds==0)
        {
          minutes=minutes-1;
          seconds=60;
        }
     document.getElementById("demo").innerHTML="<div class='nums'>"+days+" days<span class='numSeperator'>:</span >"+hours+" hours<span  class='numSeperator'>:</span>"+ minutes +" minutes <span class='numSeperator'>:</span >"+seconds+" seconds</div>";
         if(minutes==0)
             {
           hours =hours -1;
           minutes=59;
           seconds=60;

             }

     
     if(hours==0)
        {
          days=days-1;
           hours=23;
           minutes=59;
           seconds=60;
        }

         if(days==0&&hours==0&&minutes==0&&seconds==0)
             {

               clearTimeout(timer);
               document.getElementById("demo").innerHTML="00:00:00:00";
             }
}
</script>


//css
<style>
.nums{
color:#1AA855;
font-size: 48px;
}
.numSeperator
{
color:#F59E18;

}
</style>

Result ...

days:hours:58 minutes:20 seconds

Thursday, March 27, 2014

How to create SharePoint web part tabs in web part zone?

Step 1
Add your web parts into web part zone



Step 2
  1. Add html form Web Part
  2. In web part properties – chrome type set none
  3. Open in edit mode and copy past the code below
Script
var isfirstTime=true;
var myHeader="";

$(document).ready(function(){
var currentUrl=window.location.href;
var patern='PageView';
if(currentUrl.indexOf(patern)!= -1){
  //form is editing now (if form in editing mode don't apply tabs
  }
  else{
$("#CustomWebPartPTabsTable").closest('td[id*="MSOZoneCell_WebPartWP"]').closest('tbody').children('tr').each(function(){

var currentTdID=$(this).children('td').attr('id');
if(isfirstTime==false){

myHeader+='<td><div class="button-link"  ref="'+currentTdID+'" onclick="toggle_visibility('+currentTdID+');"> '+$(this).find('.ms-WPHeader h3').text();+'</div></td>';
//hide ribbon
$(this).find('.ms-WPHeader h3').closest('tr').hide();
//hide web part
$("#"+currentTdID).hide();
}
isfirstTime=false;
});
$("#CustomWebPartPTabsTable").append(myHeader);
//first time
$("#CustomWebPartPTabsTable td div:eq(0)").click();
}


});

function toggle_visibility(item) {
  $("#CustomWebPartPTabsTable").children('td').each(function(){
                if(item.id==$(this).find('div').attr('ref'))
                                {       
                     if($(this).hasClass('buttonSlected'))
                       {
                                                                                                $(this).addClass('buttonSlected');
                                                $(this).find('div').addClass('buttonSlected');

}
                      else
                       {
$("#" + item.id).toggle();
                                                                                                $(this).addClass('buttonSlected');
                                                $(this).find('div').addClass('buttonSlected');

                        }
                                }
                else
                                {
                                                $("#" + $(this).find('div').attr('ref')).hide();
                                                $(this).removeClass('buttonSlected')
                                                $(this).find('div').removeClass('buttonSlected');

                                }
                               
       
  });


}

Css
<style>
.button-link {
    padding: 10px 15px;
    background: white;
    color: black;
                font-size:12px

}
.button-link:hover {
    background: #c2e794;
                border-bottom: solid 1px Green;
    text-decoration: none;
}

.buttonSlected
{
    background: #c2e794 !important;
    border: solid 2px #c2e794 !important;
                color:black !important;
                font-size:16px !important;
    text-decoration: none;
               
}

</style>
Html
<table style=" border-top :solid #c2e794;"><tr id="CustomWebPartPTabsTable" style=" border-top : 1px  #c2e794;"></tr></table>


Result


Do you like this post?
Buy me a cup of coffe to show your appreciation!