# Datagrid Matching/Compare help

**URL:** <https://forum.kirupa.com/t/datagrid-matching-compare-help/262614>\
**Category:** flash\
**Created:** [June 7, 2008, 7:18pm UTC](https://forum.kirupa.com/t/datagrid-matching-compare-help/262614 "2008-06-07T19:18:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nubian](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@nubian](https://forum.kirupa.com/u/nubian)\
**Post date:** [June 7, 2008, 7:18pm UTC](https://forum.kirupa.com/t/datagrid-matching-compare-help/262614/1 "2008-06-07T19:18:53Z")

</div>

i’ve been searching and trying for weeks on how to compare values of two seperate datagrids.

for example lets say i have a datagrid named **mg\_dg** like this:

```php

var myDP:Array = new Array ();
myDP.addItem ({id:1, firstName:"firstName_1", lastName:"lastName_1"});
myDP.addItem ({id:2, firstName:"firstName_2", lastName:"lastName_2"});
myDP.addItem ({id:3, firstName:"firstName_3", lastName:"lastName_3"});
myDP.addItem ({id:4, firstName:"firstName_4", lastName:"lastName_4"});
my_dg.dataProvider = myDP;

```

let say i have another datagrid named **mg\_dg2** like this:

```php

var myDP2:Array = new Array ();
myDP2.addItem ({id:1, firstName:"firstName_1", lastName:"lastName_1"});
myDP2.addItem ({id:2, firstName:"firstName_2", lastName:"lastName_2"});
myDP2.addItem ({id:3, firstName:"firstName_3", lastName:"lastName_3"});
myDP2.addItem ({id:4, firstName:"firstName_5", lastName:"lastName_5"});
my_dg2.dataProvider = myDP2;

```

so if you noticed with my\_dg2 that the there is firstName\_5 and lastName\_5 but there is not one in the my\_dg datgrid.  
if i were to select from **my\_dg2** firstName\_5 and lastName\_5…what i’m looking do is something along the lines of this:

```php

var dgListener:Object = new Object ();
dgListener.cellPress = function (eObj:Object) {
		//if the selected row values from my_dg2 matches any of the row values in my_dg...
		trace("match found");
		else
		trace("no match found");
		//proceed to do something else
};
mg_dg2.addEventListener ("cellPress",dgListener);

```

so it would output “no match found”.

i’ve even spent countless hours trying to hack this out:

> **[Dynamically Searchable DataGrid Component (Flash AS 2.0)](https://waxjelly.wordpress.com/2006/08/21/dynamically-searchable-datagrid-component-flash-as-20/)**
>
> This post has been moved.

this is sorta what i’d like to accomplish but not in the sense of using a textinput component.  
it filters the datagrid of the text typed into the textinput component.

any help on how to achieve these results or could come up with a better more intuitive solution to this will greatly be appreciated.  
thank you

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 8, 2008, 3:44am UTC](https://forum.kirupa.com/t/datagrid-matching-compare-help/262614/2 "2008-06-08T03:44:23Z")

</div>

Easy fix:

```php

for(var i = 0; i<my_dg2.dataProvider.length; i++){
if(my_dg.getItemAt(i).firstName == my_dg2.selectedItem.firstName){
trace("match found!");
}else{
trace("no match found. :(");
}
}

```

It searches your whole datagrid for matching text. That code is not completely accurate, but should give you a lot of headway into your problem. Hope I helped. 😉

---

<div class="post-metadata">

**Author:** ![nubian](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@nubian](https://forum.kirupa.com/u/nubian)\
**Post date:** [June 8, 2008, 3:58pm UTC](https://forum.kirupa.com/t/datagrid-matching-compare-help/262614/3 "2008-06-08T15:58:36Z")

</div>

thank you!!  
i will give this a shot!!  
again thanks!
