Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

How to filter the text in a DataGrid correctly

Hello!

I use 2 functions to filter names in a datagrid. Anything is going wrong. Here´s an example:
When i write "maier" the result doesn´t include only the name i search for, the result includes all names where "maier" is in it. e. g. lechmaier, obermaier, ...

Please how can i fix this?

Thank´s!

Regards,
Mario
private function refilter():void {
    	filter.text = StringUtil.trim(filter.text.toLowerCase());
    	if( filter.text.length == 0)
    	userRequest.lastResult.users.user.filterFunction = null;
    	else
    	userRequest.lastResult.users.user.filterFunction = filterCompany;                        
    	userRequest.lastResult.users.user.refresh();
	}
 
	private function filterCompany( e:Object):Boolean {
    	if( String(e.usernachname).toLowerCase().indexOf( filter.text) != -1)
    	return true;      
    	return false;
	}

Open in new window

0
20one
Asked:
20one
  • 3
  • 3
1 Solution
 
Jones911Commented:
if( String(e.usernachname).toLowerCase().indexOf( filter.text) != -1)
 change to

if( e.usernachname == filter.text )
0
 
20oneAuthor Commented:
Thank´s for the answer. But the solution doesn´t work. If i write a name into the textfield, the datagrid is empty.

0
 
Jones911Commented:
I need to see more of the function and the datagrid and how you are doing this.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
20oneAuthor Commented:
This is the whole code i use for the filter.

And here´s the code of the textfield.
<mx:TextInput x="1000" y="10" change="refilter()" id="filter" editable="true"  width="237"/>

And the datagrid:
<mx:DataGrid change="eventListener(event);kunden_mutter.selectedChild=kunden_detail" id="dgUserRequest" width="100%" height="100%" x="0" y="50" dataProvider="{myData}">
              <mx:columns>
                <mx:DataGridColumn headerText="Nr." dataField="userid" itemRenderer="CustomRenderer" width="50" sortable="false"/>
                <mx:DataGridColumn headerText="Anrede" dataField="anrede" itemRenderer="CustomRenderer" width="60"/>
                <mx:DataGridColumn headerText="Nachname" dataField="usernachname" width="300" itemRenderer="CustomRenderer"/>
                <mx:DataGridColumn headerText="Vorname" dataField="username" itemRenderer="CustomRenderer" sortable="false"/>
                <mx:DataGridColumn headerText="Plz" dataField="plz" width="50" itemRenderer="CustomRenderer"/>
                <mx:DataGridColumn headerText="Ort" dataField="ort" width="200" itemRenderer="CustomRenderer"/>
                <mx:DataGridColumn headerText="Straße" dataField="strasse" width="200" itemRenderer="CustomRenderer" sortable="false"/>
                <mx:DataGridColumn headerText="Telefon Nr." dataField="tel_privat" width="150" itemRenderer="CustomRenderer" sortable="false"/>
              </mx:columns>
            </mx:DataGrid>
0
 
Jones911Commented:
This shoudl work.
if( e.usernachname.toLowerCase() == filter.text.toLowerCase() )
0
 
20oneAuthor Commented:
Now it works perfect!
Thank´s
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now