Showing posts with label SharePoint WebPart. Show all posts
Showing posts with label SharePoint WebPart. Show all posts

Thursday, September 22, 2016

Using REST API For Selecting, Filtering, Sorting And Pagination in SharePoint List

 how to work with SharePoint list items, basically performing CRUD operations, using the combination of REST API 
and jQuery Ajax. The REST URI ends with any OData query operators to specify selecting, sorting, or filtering

Selecting and sorting items:

$select :

This ' /_api/web/lists/getbytitle('test')/items' url returns all items with all possible fields or list columns. 
But what if list has more than 20-30 columns?
 It’s not good practice to get all fields. 


Syntax for this is $select=Field1, Field2, Field3 
/_api/web/lists/getbytitle('test')/items?$select=ID,Title,Employee,company

'$orderby' :


The first two specify sorting in ascending order and the third one descending order.
 It's simple, you can use '$orderby' parameter and provide the field name. 
REST service will return sorted list items in response.

Syntax: for this is $orderby=(Column Internal Name order)

Ascending Order:
/_api/web/lists/getbytitle('emp')/items?$select=ID,Title,Employee,company&$orderby= Employee asc 
Descending Order:


/_api/web/lists/getbytitle('emp')/items?$select=ID,Title,Employee,company&$orderby= Employee desc  

Filtering items:

You can filter your list to contain only items which match a simple logical expression using the $filterparameter.

Syntax: for this is $filter=(Column Internal Name operator value).
See below examples,

Filter by Title

/_api/web/lists/getbytitle('emp')/items?$filter=Employee eq ‘parth'

Filter by ID:

/_api/web/lists/getbytitle('emp')/items?$filter=ID eq 2

Filter by Date

/_api/web/lists/getbytitle('emp')/items?$filter=Start_x0020_Date le datetime'2016-03-26T09:59:32Z'

Multiple Filters

/_api/web/lists/getbytitle('emp')/items?$filter=( Modified le datetime'2016-03-26T09:59:32Z') and (ID eq 2)

Title name starts with the letter P

/_api/web/lists/getbytitle('emp')/items?$filter=startswith(Title,‘P’)

Return all items from the 'emp'list modified in May

/_api/web/lists/getbytitle('emp')/items? $filter=month(Modified) eq 5

Friday, May 20, 2016

context menu with JavaScript (Script Editor Web Part)

We script in Script Editor webpart on the page


<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".ms-list-itemLink > a").each(function(){
        this.setAttribute("onclick","ShowECBMenuForTr(this.parentNode, event); return false;");
    });
});
</script>

Thursday, May 19, 2016

How to add or Change the Placeholder Text for the Find a file search box for document libraries

You can add a Script Editor Web part on the page (and you can hide it from Script editor properties) and add a script tag to jQuery



<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>

<script> $( "#inplaceSearchDiv_WPQ1_lsparent :input").attr('placeholder','Ahmed'); </script>

Saturday, February 13, 2016

Add, Update and install WSP in SharePoint using PowerShell Script

Add WSP using the following power shell script
$wspname="C:\\name.wsp"
Add-SPSolution -Identity wspname

Upgrade a WSP using the following power shell script.

(Update-SPSolution -Identity wspname -LiteralPath Physicalpath -GACDeployment)

Update-SPSolution -Identity ListDefinition.wsp -LiteralPath 


C:\\name.wsp -GACDeployment 

Install the newly created Feature using powershell script.

(Install-SPFeature FeatureFolderName)

Install-SPFeature "ListDefinition_New_List_Feature"

Friday, February 12, 2016

How to Hide a web part for selected users in Sharepoint

JQuery:

We ll do get div id or class for particular webpart

display:none




SharePoint Feature:

Edit page


  • Edit webpart properties in current page
  • web part's properties panel expand the Advanced section, scroll to the bottom and select the Target audience to hide the web part.
  • Save your changes and test by have a group member, and a non-group member, log in and see if the web part is displayed.

When we get retrive People or Group field returning semicolon hash then Name

1;#Deepak Kumar


Get User name:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupValue;


Get User ID:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupId;

Using Split fuction:

properties.ListItem["Staff Member"].ToString();

You are going to be returned their userID and username, so it will always be returned separated by ;#.



properties.ListItem["Staff Member"].ToString().split(";#")[1];

Tuesday, January 12, 2016

Add css class to webpart cell

$('div[id$=Test]').addClass('cssClassAddedFromCode');

var addCssClassScript = "$('div[id$=Test']').addClass('cssClassAddedFromCode');";
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "AddCssClass", addCssClassScript, true);