You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by sankar <sa...@gmail.com> on 2016/12/14 09:29:42 UTC

Filter function to ArrayList?

In conventional application we often found a list/grid with a search text
box. This was easy to handle and filter the collection in Flex SDK, and
affect the list/grid UI per it's binding. 


> private function filterCollectionOnTextSearch():void
> {				
> 	gridArrayCollection.filterFunction = searchName;
> 	gridArrayCollection.refresh();
> }
> 
> private function searchName(item:Object):Boolean 
> {
> 	if (item.nickName.toLowerCase().indexOf(txtSearch.text.toLowerCase()) !=
> -1 ) return true;
> 	return false;
> }

FlexJS uses it's own ArrayList API and I didn't found any way to accomplish
the above requirement, so far. Is there any built-in way to filter the
ArrayList and refresh - and update to list/grid component per it's binding
feature?



--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-ArrayList-tp57239.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: Filter function to ArrayList?

Posted by Alex Harui <ah...@adobe.com>.
Hi Joel,

I took a look at the code.   It looks like it would work.  I'm wondering
if you considered:
1) directly accessing the underlying array instead of using super methods
2) storing the unfiltered data as an Array instead of an ArrayList.

Thoughts?
-Alex

On 1/3/17, 3:28 PM, "JoelProminic" <jo...@prominic.net> wrote:

>I updated the JIRA issue
>(https://issues.apache.org/jira/browse/FLEX-35232)
>with a modified version of the project where the visible elements of the
>FilteredArrayList are stored with the superclass logic, while the full
>list
>is maintained as a separate ArrayList instance.   This makes
>FilteredArrayList throw the appropriate itemAdded, itemRemoved, and
>itemUpdated events for the visible list (itself) rather than for the full
>list, as it did in the previous version.
>
>The updated example also automatically refreshes the list when you click
>the
>Update/Add/Remove Entry buttons, for convenience.
>
>Otherwise, the logic has the same limitations discussed above.
>
>Joel Anderson
>My Apache Flex community contribution is working on the open source
>Moonshine-IDE.com for FlexJS.
>
>
>
>
>--
>View this message in context:
>http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-Ar
>rayList-tp57239p57871.html
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: Filter function to ArrayList?

Posted by JoelProminic <jo...@prominic.net>.
I updated the JIRA issue (https://issues.apache.org/jira/browse/FLEX-35232)
with a modified version of the project where the visible elements of the
FilteredArrayList are stored with the superclass logic, while the full list
is maintained as a separate ArrayList instance.   This makes
FilteredArrayList throw the appropriate itemAdded, itemRemoved, and
itemUpdated events for the visible list (itself) rather than for the full
list, as it did in the previous version.

The updated example also automatically refreshes the list when you click the
Update/Add/Remove Entry buttons, for convenience.

Otherwise, the logic has the same limitations discussed above.

Joel Anderson
My Apache Flex community contribution is working on the open source
Moonshine-IDE.com for FlexJS. 




--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-ArrayList-tp57239p57871.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: Filter function to ArrayList?

Posted by Alex Harui <ah...@adobe.com>.
Sounds good.  I may not be able to really review this until we get back to
a regular schedule on Jan 3.  Right now I get only get a few minutes here
and there.  Thanks for working on it.

A couple of thoughts in-line...

-Alex

On 12/29/16, 3:27 PM, "JoelProminic" <jo...@prominic.net> wrote:

>I started some work on this feature.  I created a JIRA issue here:
>https://issues.apache.org/jira/browse/FLEX-35232
>
>I created a simple implementation, FilteredArrayList, that is just a
>subclass of ArrayList.
>
>I created an IFilter interface to define the filter, rather than the
>Function used by ArrayCollection.  I originally tried to use a Function,
>but
>I found that it did not convert properly in the Javascript application.
>
>This solution maintains a second ArrayList that represents the elements
>that
>match the given filter.  The ArrayList functions are overridden to update
>this list as appropriate.
>
>I confirmed that I could use FilteredArrayList with a DataGrid.  See
>TestFilteredArrayList.zip in JIRA for an example project.  Note that the
>changes will not be updated to DataGrid until you click "Refresh"
>
>Some notes:
>- This is a proof of concept.  The class needs some more robustness and
>testing before it is ready for "production"
>- I used the filtered list for the {{getItemAt}} and {{length}}
>implementation
>- For other functions that use a specific index (addItemAt, removeItemAt,
>updateItemAt), I used the index of the parent class.  This could be a bit
>unintuitive for some cases

It might be reasonable to make a read-only versions of the classes and
APIs that don't have these "write" methods so that basic implementations
can avoid the whole topic of what index means when writing.
 
>- I have not implemented getItemIndex, itemUpdated, itemUpdatedAt, and
>setItemAt
>- There is no way to read items directly from the underlying list, for
>now.
>- I have not yet created a specialized interface for this class (i.e.
>IFilteredArrayList).  I haven't seen an advantage to this, yet.

If any, the advantage would be that folks will implement different
versions with different strategies for the "write" methods.

>- I have not added any events to the functions.
>
>
>I have attached an example application as TestFilteredArrayList.zip to the
>JIRA issue.  The FilteredArrayList implementation is in:
>- src/collections/FilteredArrayList.as
>- src/collections/IFilter.as
>
>Joel Anderson
>My Apache Flex community contribution is working on the open source
>Moonshine-IDE.com for FlexJS.
>
>
>
>
>--
>View this message in context:
>http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-Ar
>rayList-tp57239p57642.html
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: Filter function to ArrayList?

Posted by JoelProminic <jo...@prominic.net>.
I started some work on this feature.  I created a JIRA issue here: 
https://issues.apache.org/jira/browse/FLEX-35232

I created a simple implementation, FilteredArrayList, that is just a
subclass of ArrayList.

I created an IFilter interface to define the filter, rather than the
Function used by ArrayCollection.  I originally tried to use a Function, but
I found that it did not convert properly in the Javascript application.

This solution maintains a second ArrayList that represents the elements that
match the given filter.  The ArrayList functions are overridden to update
this list as appropriate.

I confirmed that I could use FilteredArrayList with a DataGrid.  See
TestFilteredArrayList.zip in JIRA for an example project.  Note that the
changes will not be updated to DataGrid until you click "Refresh"

Some notes:
- This is a proof of concept.  The class needs some more robustness and
testing before it is ready for "production"
- I used the filtered list for the {{getItemAt}} and {{length}}
implementation
- For other functions that use a specific index (addItemAt, removeItemAt,
updateItemAt), I used the index of the parent class.  This could be a bit
unintuitive for some cases
- I have not implemented getItemIndex, itemUpdated, itemUpdatedAt, and
setItemAt
- There is no way to read items directly from the underlying list, for now.
- I have not yet created a specialized interface for this class (i.e.
IFilteredArrayList).  I haven't seen an advantage to this, yet.
- I have not added any events to the functions.  


I have attached an example application as TestFilteredArrayList.zip to the
JIRA issue.  The FilteredArrayList implementation is in:
- src/collections/FilteredArrayList.as
- src/collections/IFilter.as

Joel Anderson
My Apache Flex community contribution is working on the open source
Moonshine-IDE.com for FlexJS. 




--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-ArrayList-tp57239p57642.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: Filter function to ArrayList?

Posted by Alex Harui <ah...@adobe.com>.

On 12/22/16, 12:19 AM, "sankar" <sa...@gmail.com> wrote:

>JoelProminic wrote
>> Define a new bead, say FilterDataProvider, with a "filter" field.  This
>> would implement ICollection or IArrayList so that the methods return the
>> filtered data instead of the actual data.
>> 
>> When this bead is added to a container, it would use the current
>> dataProvider as the raw data, and replace the current dataProvider with
>> itself.
>
>@Alex, I have a some thought over this; Unfortunately iCollection or
>iArrayList or any collection list that has an in-built filter function
>(like
>ArrayCollection) does not available in FlexJS. So perhaps we'll need to
>filter data in a crude way which may cause memory stress.
>
>What you think about it?
>

In the pay-as-you-go philosophy, you would create an IArrayListWithFilter
that extends IArrayList, and subclass ArrayList to create an
ArrayListWithFilter.  Don't worry about memory stress until you prove it
exists.  Then the the usual response is to in-line more code which is
totally fine, because you've already proven that there are PAYG options
for those who need it.

My 2 cents,
-Alex


Re: Filter function to ArrayList?

Posted by sankar <sa...@gmail.com>.
JoelProminic wrote
> Define a new bead, say FilterDataProvider, with a "filter" field.  This
> would implement ICollection or IArrayList so that the methods return the
> filtered data instead of the actual data.  
> 
> When this bead is added to a container, it would use the current
> dataProvider as the raw data, and replace the current dataProvider with
> itself.

@Alex, I have a some thought over this; Unfortunately iCollection or
iArrayList or any collection list that has an in-built filter function (like
ArrayCollection) does not available in FlexJS. So perhaps we'll need to
filter data in a crude way which may cause memory stress. 

What you think about it?




--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-ArrayList-tp57239p57527.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: Filter function to ArrayList?

Posted by Alex Harui <ah...@adobe.com>.
Sounds great!  Go for it.  Let us know if you need help.

-Alex

On 12/21/16, 3:53 PM, "JoelProminic" <jo...@prominic.net> wrote:

>I have been thinking about this a bit over the last couple of days.  I
>think
>it could be implemented as a Bead like this:
>
>Define a new bead, say FilterDataProvider, with a "filter" field.  This
>would implement ICollection or IArrayList so that the methods return the
>filtered data instead of the actual data.
>
>When this bead is added to a container, it would use the current
>dataProvider as the raw data, and replace the current dataProvider with
>itself.
>
>When the filter field is updated, the bead would need to trigger events to
>cause the strand display to refresh appropriately.
>
>Does this sound like a good approach?
>
>Joel Anderson
>My Apache Flex community contribution is working on the open source
>Moonshine-IDE.com for FlexJS.
>
>
>
>
>--
>View this message in context:
>http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-Ar
>rayList-tp57239p57522.html
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: Filter function to ArrayList?

Posted by JoelProminic <jo...@prominic.net>.
I have been thinking about this a bit over the last couple of days.  I think
it could be implemented as a Bead like this:

Define a new bead, say FilterDataProvider, with a "filter" field.  This
would implement ICollection or IArrayList so that the methods return the
filtered data instead of the actual data.  

When this bead is added to a container, it would use the current
dataProvider as the raw data, and replace the current dataProvider with
itself.

When the filter field is updated, the bead would need to trigger events to
cause the strand display to refresh appropriately.

Does this sound like a good approach?

Joel Anderson
My Apache Flex community contribution is working on the open source
Moonshine-IDE.com for FlexJS. 




--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Filter-function-to-ArrayList-tp57239p57522.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: Filter function to ArrayList?

Posted by Alex Harui <ah...@adobe.com>.

On 12/14/16, 1:29 AM, "sankar" <sa...@gmail.com> wrote:

>In conventional application we often found a list/grid with a search text
>box. This was easy to handle and filter the collection in Flex SDK, and
>affect the list/grid UI per it's binding.
>
>
>> private function filterCollectionOnTextSearch():void
>> {				
>> 	gridArrayCollection.filterFunction = searchName;
>> 	gridArrayCollection.refresh();
>> }
>> 
>> private function searchName(item:Object):Boolean
>> {
>> 	if (item.nickName.toLowerCase().indexOf(txtSearch.text.toLowerCase())
>>!=
>> -1 ) return true;
>> 	return false;
>> }
>
>FlexJS uses it's own ArrayList API and I didn't found any way to
>accomplish
>the above requirement, so far. Is there any built-in way to filter the
>ArrayList and refresh - and update to list/grid component per it's binding
>feature?

Regulare Flex ArrayList did not support filtering either.  Filtering in
the Flex SDK is part of the much heavier and slower ArrayCollection.
FlexJS doesn't have that yet.  Volunteers are welcome to provide it.  I
would try to make the filtering as loosely coupled as possible.

-Alex