SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get count rows in a List some have longest name while I am looping through all Lists. I want it in JavaScript

share|improve this question

Use below script to list all Lists and its Item Count

var context = SP.ClientContext.get_current();
var lists = context.get_web().get_lists();

context.load(lists, "Include(Title, ItemCount)");
context.executeQueryAsync(success, fail);

function success() {
    var maxLength = 0;
    var longestTitle = '';
    var itemCount = 0;
    var enumerator = lists.getEnumerator();
    while (enumerator.moveNext()) {
        var list = enumerator.get_current();
        if(maxLength < list.get_title().length) {
             maxLength = list.get_title().length;
             longestTitle = list.get_title(); 
             itemCount = list.get_itemCount();
        }
    }
    alert(longestTitle);
    alert(itemCount);
}
share|improve this answer
    
this is my code i use to get the longest listname in my siteCollection code var listEnumerator = listCollection.getEnumerator(); while (listEnumerator.moveNext()) { var currentItem = listEnumerator.get_current(), title = currentItem.get_title(); listString += "<br>" + title; if (longest.length < title.length) longest = title; } code – Milad Francis May 31 '15 at 17:13
    
I have updated my answer – Amal Hashim May 31 '15 at 17:50
    
thnxxx for ur help :) – Milad Francis May 31 '15 at 18:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.