Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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 at 17:13
    
I have updated my answer –  Amal Hashim May 31 at 17:50
    
thnxxx for ur help :) –  Milad Francis May 31 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.