Welcome, Guest
  • Author Topic: [Flex 3] Filtering a DataGrid  (Read 12009 times)

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    [Flex 3] Filtering a DataGrid
    « on: 09/29/08, 13:33 »
    Hello, i thought i'd do this question in tutorial style. So it's at least helpful to others..

    I want to search through my datagrid to filter the content that matches a TextBox. I am currently making it so that you can use a combox to select which field you want to search through, but will post that code once it's complete.

    I have a datagrid loaded from xml content (which was taken from mysql). This content (Dataprovider) is called 'acOrder'


    This is my textbox and a search button. The button calls the function 'doFilter' in my AS script
    Code: [Select]
    <mx:TextInput id="filterTxt" width="238" toolTip="Search by status"/>
    <mx:Button id="filterButton" icon="@Embed('icons/SearchRecord.png')" toolTip="Search:" click="filtercontent()"/>

    This is the AS script functions:

    Code: [Select]
    private function filterColumn(item:Object):Boolean
    {
    var content:String = filterTxt.text
    var key:String = item.orderid

    if(content.indexOf(key) !=-1)
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    ///if the textbox is empty, it then calls back all of the data. I actually use a 'reset' button to do this as well.

    private function filtercontent():void
    {
    if (filterTxt.text.length == 0)
    {
    acOrder.filterFunction = null
    }
    else
    {
    acOrder.filterFunction = filterColumn;
    }
    acOrder.refresh()
    }


    So my question is, I have used indexOf to try to search so that only part of the string needs to match the Data. (as jorge showed in my as3 thread http://www.flash-db.com/Board/index.php?topic=18735.0).

    But why does it ONLY return 'true' on the data which matches the Entire string?

    It should be returning each row which has just PART of the string in the textfield?



    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: [Flex 3] Filtering a DataGrid
    « Reply #1 on: 09/29/08, 18:27 »
    indexOf return true if any portion matches

    [as]
    a = "this is my mother house"
    trace(a.indexOf("mother")!=-1)
    [/as]

    So trace your content, probably item.orderid is not the rigth column

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: [Flex 3] Filtering a DataGrid
    « Reply #2 on: 09/29/08, 19:01 »
    check it out.

    i did 3 traces and they contradict each other...
    Code: [Select]
    private function filterByOrderid(item:Object):Boolean
    {
    var content:String = filterTxt.text
    var key:String = item.orderid

    trace(item.orderid)
    trace(content)
    trace(content.indexOf(key)!=-1)
    if(content.indexOf(key)!=-1)
    {
    return true;
    }
    else
    {
    return false;
    }
    }


    i type in "99"

    results:

    80000095
    99
    false
    80000096
    99
    false
    80000097
    99
    false
    80000098
    99
    false
    80000099
    99
    false

    it gets the column correctly and it's value. It sees the string from textbox as 99 but then it returns False

    I also tried this line
    Code: [Select]
    if(content.indexOf("80000099")!=-1)
    but results still:

    80000099
    99
    false

    maybe does not work in flex..
    « Last Edit: 09/29/08, 19:03 by jarmanje »

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: [Flex 3] Filtering a DataGrid
    « Reply #3 on: 09/29/08, 22:19 »
    80000099 is not inside 99, but the oposite is rigth. Wrong parameters

    Jorge

    jarmanje

    • Senior Programmer
    • ****
    • Posts: 334
      • View Profile
    Re: [Flex 3] Filtering a DataGrid
    « Reply #4 on: 09/30/08, 16:22 »
    Thanks again jorge,

    I must of crossed that somehow when taking it from flash. Works perfectly now.