Hello All ,
I want to get list item count using CSOM object model ... How can I achieve this ? And which method is efficient ajax webservice call or using Jquery ?
Can anyone share the piece of code ?
Technology Tips and News
Hello All ,
I want to get list item count using CSOM object model ... How can I achieve this ? And which method is efficient ajax webservice call or using Jquery ?
Can anyone share the piece of code ?
Hi,
Please try this using spservices
$().SPServices({ operation: "GetListItems", listName: "Your_list_name", async: false, completefunc: function(xData, Status) { itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"); } }); alert(itemCount); });
Please refer this url for more information "https://spservices.codeplex.com/discussions/534802"
Regards,
Anurag
Hi,
You can try below code block in CEWP on your page.
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"></script> <script> var context; var web; var list; var targetList; (function() { // This code runs when the DOM is ready and creates a context object which is // needed to use the SharePoint object model $(document).ready(function() { getItemCount(); }); function getItemCount() { debugger; context = SP.ClientContext.get_current(); //gets the current context web = context.get_web(); //gets the web object list = web.get_lists(); //gets the collection of lists targetList = list.getByTitle("MyListName"); //get the list details context.load(targetList); context.executeQueryAsync(onGetSuccess, onGetFail); } function onGetSuccess() { console.log("List Item Count= " + targetList.get_itemCount()); } function onGetFail(sender, args) { console.log('Error:' + args.get_message()); } })(); </script>Thanks. Please mark it as answer if it helps.