1

I have a list WSR, there is view in it called 'Overdue'. I want to get the count of the items in this view using javascript. Please help

2

3 Answers 3

1

Using Full Rest API

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('your_list')/items?$select=your_field,Title",
    method: "GET",
    headers: { "accept": "application/json;odata=verbose", },
    success: function (data) {
        var cosa = complete(data.d.results, "SubProcesoId")
        console.log(JSON.stringify(cosa));
    },
    error: function (data) {
        console.log(data);
    }
});

function complete(items,propertyName)
{
    var result = [];
    var obj = {};
    $.each(items, function(index, item) {
        var obj = {};
        obj.subp = item.SubProcesoId;
        obj.title = item.Title;
        result.push(obj);
    });
    return result;
}

This will return a JSON object with all the elements in the list. Using the underscorejs library, you can group by and get the count per repeted item.

console.log( _.groupBy(orders, function(obj){
    return obj["subp"];
}));

This is the example of my test https://jsfiddle.net/hetdapuv/

1

When you query the Lists.asmx web services, it's result set XML response already contains the row count in an attribute value of the rs:data element which is what you need if you target the specific view and don't exceed the query RowLimit setting. Otherwise, you'll have to count.

Marc D Anderson's SPServices library now on GitHub has awesome documentation and samples.

1

If the View is displayed

Add a Content Editor WebPart below the View on the page

and execute:

console.log('There are', ctx.ListData.Row.length,' items in this View (page)');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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