Hi Guys,
Thanks for visiting our blog .
In our previous post we were seen how ecma scripts works. To Know more ECMA Script Click here.
In our current post we are going to see how we can get the count of list items inside Sharepoint lists. without using visual studio or server object model.
Before client object model introduced . if we want to implement the same concept we should have to write server side code in C# but now we can get the items count without touching the visual studio.
Now we are going to look at.
1. Creation of Site pages .
2. How to add a content editor web part.
3. How to write Script in Content Editor webpart.
Step :1 Create a site page in Sharepoint site .
Step :2 Add content editor webpart into the page by selecting
--> Edit Page
-->Add web part
--> webpart gallery
--> Media and Content (Category)
-->Content editor Web part .
-->Add the Script inside the Html, Source.
--> You cane See the Items count inside the list
Script Description :
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");
var objContext = null;
var objWeb = null
var objList = null;
var objItem = null;
function MainFunction() {
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists().getByTitle("Product"); // Here we are passing the list name
objContext.load(objList);
objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
alert('Item Count: ' + objList.get_itemCount());
}
function onFail(sender, args) {
alert('Some error has occured.');
}
</script>
ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");
This functions stops loading the script until the page completly gets loaded .
Once the page loaded completly then it acts as a main function to start the script running.
sp.js
This is the heart file for ecma script . it loads from layout folder in 14 hive . if it does not loads then we cant work with ECMA Script .
This is a sample of ECMA Script with SharePoint .In our netx post we will see how to work with ECMA Script using Visual Webpart.
Thanks for visiting our blog Hope to see you again for new posts.
Related Post
ECMA Script
- Get List Field Type using ECMA Script in SP Hosted Apps
- Get Choice Field Type Values using ECMA Script
- Executing Search Queries using ECMA Script in SharePoint 2013
- Create Site Column and Adding it to Content Type using ECMA Script
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Get Lookup Column Value using ECMA Script
- Create Folder in document Library using ECMA Script in SharePoint Hosted Apps
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- How to get List Items Count from SP List Using Visual webpart and ECMA script in SharePoint 2010
- SharePoint Client Object Model using ECMAScript in 2013
SharePoint 2010
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Basics: Difference between Synchronous Events and Asynchronous Events in SharePoint
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
- Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint Interview Questions and Answers..
- What are Event Receivers and How to Create Sample event Receivers and attach to List/ Doc Library ?
- Export SharePoint Search Crawl log to CSV File.
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- SharePoint Modal Dailoge to Open Page
- SPDataSource in SharePoint.
- Capacity planning and Sizing in SharePoint 2010
- Enable 'Save site as Template' in Publishing Sites by using SharePoint Designer
- Read Enhanced Rich Text Values in SharePoint
- What is Web part life Cycle in SharePoint 2013 and SharePoint 2010
- How to Hide Controls in SharePoint New Form Based on User using ECMA Script.
- What is the Content Type for Custom List in SharePoint 2013, SharePoint 2010
- What is calculated column in SharePoint 2013 ,2010
- Create Meetings by using Exchange Server API
Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info. view
ReplyDelete