0

I have 3 dropdown menus, in those 4 fields I have choices to query a SharePoint 2010 list using SPServices

Dropdown filters are: Year, Month, Company List fields are: Year, Month, Company, Department

What I want is to filter the retrieved items based on the values of that 4 dropdowns and then with the result sum all values in the field Department

        $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "List guid", 
        viewName: "View guid",
        CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Department' /></ViewFields>",
        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var liHtml =$(this).attr("ows_Title");
                var Department=$(this).attr("ows_Department");
        }
    });

How can I only retrieve the filter items and sum the values of that field, CAMLQuery ?

0

CAML can only filter, and is like telling the Server "hey, give me this subset of data"

If retrieving all data is no issue, it is simpler to do the filtering Client-Side.

Your current code is already looping all rows, it takes less complex JavaScript to do the filtering.
And while you loop, you sum by Department

Do look in the native JavaScript methods on the Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

It trumps jQuery in performance

You especially want to learn the .filtermethod

Ofcourse you can let the Server do part of the work with CAML, but with the SharePoint Framework future you are going to do it more and more with Client-Side technlogies (or REST to tell the Server to limit datasets)

0

You can do this on the form using a Cascading Dropdown function that is also part of SPServices. You do not need to filter on them with a query, and the form selection of the department can be dynamic. This would require each one of the dropdown filters to be in a list. You would create a one-to-one relationship with the items using lookup fields. It is really neat, and it is some good looking functionality on the form. I think this would suit your needs the best.

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.