0

I want to subset an array.I have the following array

public var sellAmount:ArrayCollection=new ArrayCollection([
     {month:"Jan", sell:2000},
     {month:"Feb", sell:5000},
     {month:"Mar", sell:4000},
     {month:"Apr", sell:6000},
     {month:"May", sell:3000},
     {month:"Jun", sell:9000},         
     {month:"Jul", sell:1100},
     {month:"Aug", sell:4000},
     {month:"Sep", sell:1000},
     {month:"Oct", sell:500},
     {month:"Nov", sell:4000},
     {month:"Dec", sell:3000}
     ])

Now based on user requirement I want to select a range of sell data for some month.For example sometime it may be sells data from Apr to Dec,sometime may be Jul-Oct.How can I do that without hampering the original array

0

2 Answers 2

1

You can use ArrayCollection.filterFunction, though your use of strings for the month makes it a tad more difficult:

function filterSalesData(startMonth:uint, endMonth:uint) {
    sellAmount.filterFunction = monthRangePredicate;
    sellAmount.refresh();

    function monthRangePredicate(obj : Object) {
        var months : Array = ["Jan", "Feb", "Mar", etc]; // TOOD: promote to class level

        var monthIndex : uint = months.indexOf(obj.month);

        return (monthIndex >= startMonth && monthIndex <= endMonth);
    }
}

filterSalesData(6, 9); // july to october
filterSalesData(3, 11); // april to december
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a Lot.But I did it in slightly different way.Instead of using data as ArrayCollection, I used it as array and then I used slice function.
0

Create a filterFunction for the ArrayCollection which applies the filter as required.

Comments

Your Answer

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