2

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.

1

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

Example:

SP.SOD.executeFunc("sp.js", "SP.ClientContext", () => { 
    var ctx = SP.ClientContext.get_current();
    var viewXml = `<View>
                        <Aggregations Value='On'>
                            <FieldRef Name='Month' Type='COUNT'/>
                        </Aggregations>
                        <Query>
                            <Where>
                                <IsNotNull>
                                    <FieldRef Name='Month' Type='Text'/>
                                </IsNotNull>
                            </Where>
                        <GroupBy Collapse='TRUE' GroupLimit='100'>
                            <FieldRef Name='Month' />
                        </GroupBy>
                        <OrderBy>
                            <FieldRef Name='Month' Ascending='TRUE' />
                        </OrderBy>
                    </Query>
                </View>`;
    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) => {
        console.log("err",a.get_message());
    });
});

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.