This Question is Answered

15 "helpful" answers available (3 pts)
6 Replies Last post: Jul 15, 2008 12:12 AM by tdeng

how to use wildcard search (%,_) with RecordGrid?

Jul 14, 2008 6:35 AM

Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008

Hi,


How to use wild card search (%,_) with RecordGrid.


Thanks

Rajiv

Click to view Duke's profile Curl Duke 155 posts since
Oct 17, 2007
1. Re: how to use wildcard search (%,_) with RecordGrid? Jul 14, 2008 11:39 AM
I think you would use the RecordSet.select method and define your own RecordFilter that would do the kind of search that you want. I don't think we have something already built for the kind of search you are talking about. I don't know what you mean by (%,_).
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
2. Re: how to use wildcard search (%,_) with RecordGrid? Jul 14, 2008 8:01 PM
in response to: Duke
As Duke said, you could create your own RecordFilter for doing this, and if the amount of data is not huge, using regular expression may be a good choice.
For Duke's question, I think (%,_) here refers to wildcards used in SQL (% stands for any character string, _ stands for any character).
Click to view RajivGu's profile Level 6 RajivGu 81 posts since
Apr 2, 2008
3. Re: how to use wildcard search (%,_) with RecordGrid? Jul 14, 2008 10:12 PM
in response to: tdeng

hi tdeng,

you undesrstand it correctly , % , _ are used as wild card search in SQL Query for matching record.(e.g like name = 'A%')

Here I am using RecordGrid to show the record. Recordset is populated from querying the SQLite Database.

Next time when I want to search the record in RecordGrid, I want to use the recordset use to populate the RecordGrid.

I want to prevent the overhead involve in querying the SQLite DB again. So I need information on how to use this wildcard search

with recordset or RecordGrid filter.

Thanks

Rajiv

Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
4. Re: how to use wildcard search (%,_) with RecordGrid? Jul 15, 2008 12:08 AM
in response to: RajivGu
If you want to reuse the RecordSet for filtering in RecordGrid, what you need will just create your own RecordFilter and apply it to RecordGrid.records, which is a RecordView generated from RecordGrid.record-source internally.

Here is a sample for you:

{curl 5.0, 6.0 applet}
{let people:RecordSet =
    {RecordSet
        {RecordFields
            {RecordField 
                "First", caption = "first name", domain = String
            },
            {RecordField 
                "Last", caption = "last name", domain = String
            },
            {RecordField 
                "Age", caption = "age", domain = int
            }
        },
        {RecordData First = "John", Last = "Smith", Age = 25},
        {RecordData First = "Jane", Last = "Smith", Age = 29},
        {RecordData First = "Jane", Last = "Jones", Age = 28},
        {RecordData First = "Ben"      , Last = "Abrams", Age =    5},   
        {RecordData First = "Sam"      , Last = "Jones", Age =     6},   
        {RecordData First = "Nigel"     , Last = "Stevens", Age =   7},   
        {RecordData First = "Bert"      , Last = "Stevens", Age =  8},   
        {RecordData First = "Pat"       , Last = "Linden", Age =    9},   
        {RecordData First = "Mat"      , Last = "Abrams", Age =   10},  
        {RecordData First = "John"     , Last = "Rogers", Age =    11},  
        {RecordData First = "Dan"      , Last = "Abrams", Age =   12},  
        {RecordData First = "Chris"     , Last = "Abrams", Age =   13},  
        {RecordData First = "Glenn"    , Last = "Abrams", Age =   14},  
        {RecordData First = "Doug"     , Last = "Jones", Age =     15},  
        {RecordData First = "Susan"   , Last = "Rogers", Age =    16},  
        {RecordData First = "Joan"     , Last = "Smith", Age =      17},  
        {RecordData First = "Tom"      , Last = "Frankel", Age =    18},  
        {RecordData First = "Sarah"    , Last = "Frankel", Age =    19},  
        {RecordData First = "John"     , Last = "Jones", Age =     20},  
        {RecordData First = "Pam"      , Last = "Frankel", Age =   21}
    }
}
{let rg:RecordGrid = 
    {RecordGrid
        record-source = people, height = 5cm, width = 16cm,
        column-selection-enabled? = true
        ,
        filter-menu-proc =
            {proc {array:{Array-of MenuItem}, cell:RecordGridCell}:{Array-of MenuItem}
                {array.clear}
                {array.append
                    {MenuAction
                        label = "customized-filter",
                        {on Action do
                            {let fld-name:DropdownList = {DropdownList "First", "Last"}}
                            {let filter-cond:TextField = {TextField}}
                            
                            {popup-message
                                {VBox
                                    {HBox "Field Name", fld-name},
                                    {HBox "data containing this string:", filter-cond}
                                }
                            }
                            
                            let rf:RecordFilter =
                                {RecordFilter
                                    {proc {r:Record}:bool
                                        {if {r[http://fld-name.value|http://fld-name.value].find-string
                                                filter-cond.value} != -1 then
                                            {return true}
                                         else
                                            {return false}
                                        }
                                    }
                                }
                            {set rg.records.filter = rf}
                        
                        }
                    }
                }
                {return array}
            } 
    }
}
{VBox
    rg
}


Message was edited by: tdeng
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
5. Re: how to use wildcard search (%,_) with RecordGrid? Jul 15, 2008 12:10 AM
in response to: tdeng
please replace the following code (it was formated by this web server wrongly)
{if {rhttp://fld-name.value.find-string

with

{if {r http:// fld-name.value .find-string
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
6. Re: how to use wildcard search (%,_) with RecordGrid? Jul 15, 2008 12:12 AM
in response to: tdeng
Oops, too bad. please just delete

http://fld-name.value|

in my original post.