I need to calculate the number of group in my grouping view of SharePoint list. we can also calculate the number of different value in the column.

Any idea how we can do that using JSOM.


You can use the renderListData function on a list with JSOM to do the grouping.


SP.SOD.executeFunc("sp.js", "SP.ClientContext", () => { 
    var ctx = SP.ClientContext.get_current();
    var viewXml = `<View>
                        <Aggregations Value='On'>
                            <FieldRef Name='Month' Type='COUNT'/>
                                    <FieldRef Name='Month' Type='Text'/>
                        <GroupBy Collapse='TRUE' GroupLimit='100'>
                            <FieldRef Name='Month' />
                            <FieldRef Name='Month' Ascending='TRUE' />
    var result = ctx.get_web().get_lists().getByTitle('ListTitle').renderListData(viewXml);
    ctx.executeQueryAsync(() => {
        var res = JSON.parse( result.get_value());
        console.log("Group Count: ",  res.Row.length); 
        console.log("res", res);
    },(s,a) => {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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