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
  • Possible duplicate of How to get all items in a view using REST API Commented May 19, 2017 at 16:56
  • If the answer was helpful could you remove it from the SO unanswered list, by marking it as answered, tnx Commented Jun 4, 2017 at 7:53

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)');

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.