如何在 Flex datagrid dataProvider 4 中搜索字符串?

发布于 2024-09-11 05:26:45 字数 1128 浏览 11 评论 0原文

我尝试使用filterFunction没有得到任何结果,看看这个例子:

[Bindable]
public  var SearchLoadlistOneDP:ArrayCollection;


public function SearchList():void {


 SearchLoadlistOneDP.filterFunction = filter;
 SearchLoadlistOneDP.refresh()


}


public function filter(item:Object):Boolean
{
 var beginsWithString:String = SearchLoadlistOneInput.text;



 return String(item["email"]).indexOf(beginsWithString) == 0;
}

我使用了这样的数据网格:

<mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail" creationComplete="LoadlistOne(0)">


     <mx:columns>
      <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
      <mx:DataGridColumn headerText="E-mail" dataField="email"/>
      <mx:DataGridColumn headerText="Nome" dataField="nome"/>
     </mx:columns>


    </mx:DataGrid>

和这样的文本输入:

<s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

但不幸的是我无法得到任何结果,并且数据网格已经有来自数据库的数据已经列出了数据它。

有谁可以帮忙吗,现在谢谢大家了

I tried using filterFunction not get any results, check out this example:

[Bindable]
public  var SearchLoadlistOneDP:ArrayCollection;


public function SearchList():void {


 SearchLoadlistOneDP.filterFunction = filter;
 SearchLoadlistOneDP.refresh()


}


public function filter(item:Object):Boolean
{
 var beginsWithString:String = SearchLoadlistOneInput.text;



 return String(item["email"]).indexOf(beginsWithString) == 0;
}

And I used the datagrid like this:

<mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail" creationComplete="LoadlistOne(0)">


     <mx:columns>
      <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
      <mx:DataGridColumn headerText="E-mail" dataField="email"/>
      <mx:DataGridColumn headerText="Nome" dataField="nome"/>
     </mx:columns>


    </mx:DataGrid>

And text input like this:

<s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

But unfortunately I can not any results, and the datagrid already has data from the database already has data listed on it.

Can anyone help?, Thank you all now

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜雨飘雪 2024-09-18 05:26:45

您的过滤函数应如下所示。我已经使用这个方法有一段时间了,没有遇到任何问题。这适用于 Flex 3 和 Flex 3。 4.

private function filter(item:Object):Boolean{

    //this is going to return true if we don't have anything to search by, which will return 
   //all items the the datagrid
    if(SearchLoadlistOneInput.text == ""){
    return true;
    }

     //now search the string and see if we have a match//
    if(item.email.toLowerCase().search(SearchLoadlistOneInput.text.toLowerCase()) != -1){
       return true;
    }

    return false;
}

Here is what your filter function should look like. I have been using this method for awhile and have had no problems with it. This works with Flex 3 & 4.

private function filter(item:Object):Boolean{

    //this is going to return true if we don't have anything to search by, which will return 
   //all items the the datagrid
    if(SearchLoadlistOneInput.text == ""){
    return true;
    }

     //now search the string and see if we have a match//
    if(item.email.toLowerCase().search(SearchLoadlistOneInput.text.toLowerCase()) != -1){
       return true;
    }

    return false;
}
醉城メ夜风 2024-09-18 05:26:45

Flex SDK 4.0.0,这对我有用:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="_init();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            public  var SearchLoadlistOneDP:ArrayCollection;

            private function _init() :void
            {
                SearchLoadlistOneDP = new ArrayCollection();
                SearchLoadlistOneDP.addItem({id: 1, email: '[email protected]', name:'Bill'});
                SearchLoadlistOneDP.addItem({id: 2, email: '[email protected]', name:'Todd'});
                SearchLoadlistOneDP.addItem({id: 3, email: '[email protected]', name:'Beth'});
                SearchLoadlistOneDP.addItem({id: 4, email: '[email protected]', name:'Tiffany'});
            }

            public function SearchList():void {
                SearchLoadlistOneDP.filterFunction = filter;
                SearchLoadlistOneDP.refresh()
            }


            public function filter(item:Object):Boolean
            {
                var name:String = String(item["email"]);
                var beginsWithString:String = SearchLoadlistOneInput.text;

                return name.indexOf(beginsWithString) == 0;
            }
        ]]>
    </fx:Script>

    <mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail">


        <mx:columns>
            <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
            <mx:DataGridColumn headerText="E-mail" dataField="email"/>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
        </mx:columns>


    </mx:DataGrid>


    <s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

</s:Application>

Flex SDK 4.0.0, This works for me:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="_init();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            public  var SearchLoadlistOneDP:ArrayCollection;

            private function _init() :void
            {
                SearchLoadlistOneDP = new ArrayCollection();
                SearchLoadlistOneDP.addItem({id: 1, email: '[email protected]', name:'Bill'});
                SearchLoadlistOneDP.addItem({id: 2, email: '[email protected]', name:'Todd'});
                SearchLoadlistOneDP.addItem({id: 3, email: '[email protected]', name:'Beth'});
                SearchLoadlistOneDP.addItem({id: 4, email: '[email protected]', name:'Tiffany'});
            }

            public function SearchList():void {
                SearchLoadlistOneDP.filterFunction = filter;
                SearchLoadlistOneDP.refresh()
            }


            public function filter(item:Object):Boolean
            {
                var name:String = String(item["email"]);
                var beginsWithString:String = SearchLoadlistOneInput.text;

                return name.indexOf(beginsWithString) == 0;
            }
        ]]>
    </fx:Script>

    <mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail">


        <mx:columns>
            <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
            <mx:DataGridColumn headerText="E-mail" dataField="email"/>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
        </mx:columns>


    </mx:DataGrid>


    <s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

</s:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文