in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Filtering on column containing html

Last post 9/6/2007 7:00 AM by Mehul Harry (Developer Express). 5 replies.
Page 1 of 1 (6 items)
Sort Posts:
Previous Next
  • 8/30/2007 5:12 PM

    Filtering on column containing html

    Hi,

      I have a grid in which one of the columns is composed of html (i.e. <span class='myCss' style='line-height:160%; cursor:default'>mydata</span>).  To make it render in the column correctly, I catch the HtmlDataCellPrepared and do a Server.HtmlDecode() on the column where this data goes.

      However, when I have the FilterRow on and the user tries to filter on this column, the results are based on the entire html (i.e. if I put "span", it will show all the rows even though what's showing is only "mydata").  I found a way to filter the data by using the percent "%" symbol.  However, I want to make this transparent for my users.

     

      Is there a simple fix/workaround for this issue? 

      If not, can I have another hidden column with the actual data so when the filtering happens I can change the column name to the hidden one? 

      If so, how can I intercept a callback for applying filtering? 

      As a last resort, can I intercept, on the client side, the filtering call before it goes to the server so I can add the percent "%" there?

     

     

    Thanks,

    Eben
     

  • 8/30/2007 10:57 PM In reply to

    Re: Filtering on column containing html

    Hi Eben,

    >>Is there a simple fix/workaround for this issue?

    Yes, there is a property called FilterMode which can be set for DisplayText. In the columns collection click, Settings-> Choose the column --> Set FilterMode=DisplayText.

    Note: Filtering Help Topic : Filtering by display text is ignored in Server mode.

    Alternatively, you can try using a combobox with set values, instead of a textbox where the user can freely type anything. In this tutorial, the column's combobox is bound to the database but you can also define you own items in the PropertiesComboBox.Items collection.

    Use a ComboBox to filter data instead of textbox


    Filed under:
  • 9/5/2007 4:25 PM In reply to

    Re: Filtering on column containing html

     Hi Mehul,

      I tried changing the FilterMode to DisplayText, however I still get the same behavior as before.  It seems the grid doesn't care if it's html or not as DisplayText since it searches the whole thing.  Could be because I'm actually doing the html decoding when the cell is being rendered (maybe this is what I'm doing wrong).

     

      Any other tips or suggestions?

     

     

    Thanks,

    Eben
     

  • 9/5/2007 8:14 PM In reply to

    Re: Filtering on column containing html

    Hi Eben,

    I see what you're trying to do now and there is an easier way. First, you don't need to decode the html. For this column that contains the html, set the Columns->PropertiesTexEdit->EncodeHTML property to FALSE so the html will not be stripped. Second, you don't need to use the span tag for setting your styles. Instead, for the same column, use the Columns->Styles->CellStyle->CSSClass property.

    Now filtering should not be a problem even with FilterMode set to Value. I just did a quick test and verified this is possible.

    Thanks. 

    Filed under: ,
  • 9/5/2007 8:58 PM In reply to

    Re: Filtering on column containing html

    HI Mehul,

      Thanks for the quick response!

      The Columns->PropertiesTexEdit->EncodeHTML change did the trick and now I no longer have to do an html decode.

      However, I can't put the class name where you indicated because I am placing multiple spans in a single cell.  In addition, I tried the search again and when I do a '%P' search (because of the P in "span") all of the rows come back telling me it's still searching the html.
     

     

    Thanks,

    Eben
     

  • 9/6/2007 7:00 AM In reply to

    Re: Filtering on column containing html

    Hi Eben,

    You can remove the html tag, span, from being considered as a search criteria. The code below will not return any rows when the user searches for span. However, if there is some valid wording like span in the column then it'll also not be returned. Since you're using html tags within this column then this is the drawback.

        protected void ASPxGridView1_ProcessColumnAutoFilter(object sender, ASPxGridViewAutoFilterEventArgs e)
        {
            if ((e.Column.FieldName == "HtmlColumn") && (e.Criteria.ToString().ToLower().Contains("span")))
            {
                e.Criteria = "";
            }
        }
     
    Thanks.

    Filed under: ,
Page 1 of 1 (6 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED