Alpha Video Training
Results 1 to 17 of 17

Thread: Highlighting Search String in Grid Search

  1. #1
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default Highlighting Search String in Grid Search

    I have a grid component with a search box. When I search for a term, how do I get the results to be displayed with the search term highlighted? Thanks for any help.

  2. #2
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default Clarification

    I just want to clarify my previous post. I do not know if this is possible, I saw another thread similar, but it didnt seem to apply in this situation. I mostly would like the highlighting, or bolding, to happen if I search for a string in an entry, then the result would appear with the search string highlighted, or bolded. The customer is requesting this, otherwise I wouldnt be that concerned, but it is a nice feature to have. If you dont think this is possible, please let me know. Thanks.

  3. #3
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,696

    Default

    There is no built in ability to do this. However you could add it with a little bit of Xbasic code added to your A5W page that contains the grid.

    First look at the HTML source of your page with the grid as it is displayed in your browser. You need to find the textbox control for the serach term. It will look something like:
    HTML Code:
    <input id="BIG_grid_S_FIRSTNAME" size="40" maxlength="200"  class="AirportInput" type="TEXT" name="BIG_grid_S_FIRSTNAME" value="" >
    The above is the firstname search box in a grid named "big_grid". make a note of the value in the name, in this case BIG_grid_S_FIRSTNAME. This will be a variable on your A5W page that contains the user's input.

    Now add some Xbasic code to your A5W page to modify the grid output before it is displayed. This means your code needs to be added after the a5w_run_component() call but before the ?x_out.Output.Body.Grid_HTML. In your Xbasic, you'll simply wrap the string you want to highlight with some HTML markup.

    Using the example above, the following would highlight your search term by changing the text color to red. You could apply fancier formatting if desired using different HTML markup.
    Code:
    if eval_valid("BIG_grid_S_FIRSTNAME")
        x_out.Output.Body.Grid_HTML = stritran(x_out.Output.Body.Grid_HTML,BIG_grid_S_FIRSTNAME,"<font color=red>" + BIG_grid_S_FIRSTNAME + "</font>")
    end if

  4. #4
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default

    Thanks a lot Lenny, works great!

    If anyone else trys to use this code, the closing " is misplaced.

  5. #5
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,665

    Default Next search?

    I gave this ago but two things happened I need help with - first the actual html comands displayed not the bold or color and when I selected next page to list it failed because the html codes were now in the search. Any ideas?

  6. #6
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default

    Check your quote placement. That was my problem. If that doesnt work, post a snippet of your code, and i'll take a look.

  7. #7
    Former Alpha Employee Edward Larrabee's Avatar
    Real Name
    Edward Larrabee
    Join Date
    Nov 2002
    Location
    New Hampshire
    Posts
    1,385

  8. #8
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,696

    Default

    Peter, first review Ed's link above for more detailed instructions than what I had originally posted. If you are still having a problem, please post your specific code. It sounds like you are doing an stritran() on the search part instead of the grid HTML. That would then cause the HTML tags to get inserted in the same place and be shown in the search part.

    Quote Originally Posted by peteconway
    I gave this ago but two things happened I need help with - first the actual html comands displayed not the bold or color and when I selected next page to list it failed because the html codes were now in the search. Any ideas?

  9. #9
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,696

    Default

    Thanks for pointing that out. Sorry about the confusion, I had composed the Xbasic code right here in my browser instead of Alpha Five where the syntax would have been verified for me. I have edited my original post to fix the quote placement.

    Quote Originally Posted by acidcigarfiend
    Thanks a lot Lenny, works great!

    If anyone else trys to use this code, the closing " is misplaced.

  10. #10
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,665

    Default Here is the source.

    When I use this the next page search fails because it now has HTML in it and When it does display it shows <font color=blue><b>mozart</b></font>, Wolfgang Amadeus (Johann Chrysostom) (1756-1791). In the grid.

    <html>
    <head>



    <%a5
    Delete tmpl_dwbsearch
    DIM tmpl_dwbsearch as P
    tmpl_dwbsearch = a5w_load_component("dwbsearch")
    'Following code allows you to override settings in the saved component, and specify the component alias (componentName property).
    'Tip: Keep the componentName property short because this name is used in page URLs, and it will help keep the URLs short.
    'Each component on a page must have a unique alias (componentName property).
    with tmpl_dwbsearch
    componentName = "dwbsearch"
    end with
    '=======================================compute the HTML for the Component=======================================
    delete x_dwbsearch
    dim x_dwbsearch as p
    tmpl_dwbsearch.request = request
    tmpl_dwbsearch.session = session
    tmpl_dwbsearch.response = response
    tmpl_dwbsearch.serversetting = serversetting
    tmpl_dwbsearch.PageVariables = local_variables()
    x_dwbsearch = a5w_run_Component(tmpl_dwbsearch)
    '=============================================================================================================
    if x_dwbsearch.RedirectURL <> "" then
    response.redirect(x_dwbsearch.redirectURL)
    end
    end if


    ?x_dwbsearch.Output.Head.JavaScript
    ?x_dwbsearch.Output.Head.CSS_Link

    if (eval_valid("dwbsearch_s_Keyword")) then
    x_dwbsearch.Output.Body.Grid_HTML = stritran(x_dwbsearch.Output.Body.Grid_HTML, dwbsearch_s_Keyword, "<font color=blue><b>" + dwbsearch_s_Keyword + "</b></font>")
    end if

    %>
    <!--Alpha Five Temporary Code Start - Will be automatically removed when page is published -->
    <!--CSS for tmpl_dwbsearch -->
    <link rel="stylesheet" type="text/css" href="file:///C:\Program Files\A5V7/css/Parallel/style.css">
    <!--Alpha Five Temporary Code End -->


    <meta name="generator" content="Alpha Five HTML Editor">
    <title></title>
    </head>
    <body bgColor=#f3f2f2 background="">
    <p align=center><input type="image" id="image1" name="image1" src="dwb.jpg"></p>
    <p>
    <br>
    <table align=center>
    <tr>
    <td><%A5 ?x_dwbsearch.Output.Body.Grid_Echo %></td>
    </tr>
    <tr>
    <td><%A5 ?x_dwbsearch.Output.Body.UpdateErrors %></td>
    </tr>
    <tr>
    <td><%A5 ?x_dwbsearch.Output.Body.Search_HTML %></td>
    </tr>
    <tr>
    <td><%A5 ?x_dwbsearch.Output.Body.Grid_HTML %></td>
    </tr>
    <tr>
    <td><%A5 ?x_dwbsearch.Output.Body.DetailView_HTML %></td>
    </tr>
    </table></p>
    </body></html>

  11. #11
    Former Alpha Employee Edward Larrabee's Avatar
    Real Name
    Edward Larrabee
    Join Date
    Nov 2002
    Location
    New Hampshire
    Posts
    1,385

    Default

    You will have to clear the search before running another one, or create a script that reverses the search and replace.

  12. #12
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,665

    Default OK - but what about the html showing up.

    Is there a trick to this, html (memo) or whatever (I glad I'm not going crazy)
    <font color=blue><b>Mozart</b></font>, Wolfgang Amadeus (Johann Chrysostom) (1756-1791).
    . Also IE still does not want to display special characters in html, I can't find an answer fo this anywhere. How can I force it to display what A5 want's iy to?
    e.g.Köchel, Ludwig (Alois Ferdinand) NOT K?l, Ludwig (Alois Ferdinand) (1800-1877)

  13. #13
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,696

    Default

    The issue is that your search term, mozart, appears in each of the links for the grid navigation. The links will contain something like dwbsearch_s_Keyword=mozart in them. The stritran simply looks for all occurances of mozart and changes them all. There are a few different ways you can prevent this from happening. Here is probably the simplest, though maybe not the most elegant:
    Code:
    if (eval_valid("dwbsearch_s_Keyword")) then
        dim tmp_txt as c
        tmp_txt = "dwbsearch_s_Keyword=" + dwbsearch_s_Keyword
        'temporarily replace the search term in the link with a placeholder
        x_dwbsearch.Output.Body.Grid_HTML = stritran(x_dwbsearch.Output.Body.Grid_HTML,tmp_text,"$$$$")
        'highlight the search term in the grid
        x_dwbsearch.Output.Body.Grid_HTML = stritran(x_dwbsearch.Output.Body.Grid_HTML, dwbsearch_s_Keyword, "<font color=blue><b>" + dwbsearch_s_Keyword + "</b></font>")
        'change the link placeholders back to the original state
        x_dwbsearch.Output.Body.Grid_HTML = stritran(x_dwbsearch.Output.Body.Grid_HTML,"$$$$",tmp_text)
    end if
    The code above uses "$$$$" as a temporary placeholder for the search string within the URLs. You can use any value, as long as it is something that will never appear in your data itself. If for some reason your data might contain $$$$, you would need to change this.

    Quote Originally Posted by peteconway
    When I use this the next page search fails because it now has HTML in it and When it does display it shows <font color=blue><b>mozart</b></font>, Wolfgang Amadeus (Johann Chrysostom) (1756-1791). In the grid.

  14. #14
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,665

    Default Many thanks Lenny

    I'll give it a go - what about the special characters.

  15. #15
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default

    now that ive checked this out some more, the first page works fine and highlights the search terms perfectly, but if there are multiple pages, page 2 doe s not work. The search field now contains <strong><font color=0066CC> constitutional </strong></font> and nothing is highlighted in the grid. Are there any ideas out there for how to make this work for all pages? Thanks

  16. #16
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,696

    Default

    Chris, this is the same problem Peter has brought up. Have you tried the solution I tried 2 posts above yours?

    Quote Originally Posted by acidcigarfiend
    now that ive checked this out some more, the first page works fine and highlights the search terms perfectly, but if there are multiple pages, page 2 doe s not work. The search field now contains <strong><font color=0066CC> constitutional </strong></font> and nothing is highlighted in the grid. Are there any ideas out there for how to make this work for all pages? Thanks

  17. #17
    Member
    Real Name
    Chris Dickey
    Join Date
    Jan 2006
    Posts
    28

    Default

    Actually I had forgotten to publish it when I posted the first one. It works great. Thanks.

Similar Threads

  1. Grid Search Button Visible Behavior
    By Bob Moore in forum Web Application Server v6
    Replies: 4
    Last Post: 08-08-2005, 04:33 PM
  2. Grid component search part?
    By David Brown in forum Web Application Server v6
    Replies: 1
    Last Post: 06-01-2005, 07:43 PM
  3. Doing a Search loses my grid filter
    By Ken King in forum Web Application Server v6
    Replies: 0
    Last Post: 05-13-2005, 02:11 PM
  4. Grid Search
    By Phil Rolf in forum Web Application Server v6
    Replies: 4
    Last Post: 03-26-2005, 05:48 PM
  5. Search Field for string
    By CapeMayAl in forum Alpha Five Version 5
    Replies: 0
    Last Post: 08-09-2004, 12:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •