Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by JOR on Dec 11, 2008 11:56
open dhtmlx forum
Custom text_filter that ignores HTML

Hi, I'm having difficulty figuring out how to do a custom text_filter using the built in #text_filter header item.  I have a column which contains a hyperlink but I only want to filter on the textContent of the cell and not the value.  Meaning the cell = "<a href='somelink.aspx?sdsdfsdf'>My Title</a>"  But when I type "s" into the text_filter the row doesn't hide because "s" if found in the value.  I only want to show rows where the actual visable text contains the filter term.  How can I implement this?

I thought about implementing an extra hidden column and overriding the filterBy and really filter the text only column but that seems a bit unneccessary.  Is there a way I can do this with a customized filterBy or onFilterStart function?


Answer posted by Support on Dec 12, 2008 09:16
If you  not using srnd|paging mode - you can use custom version of link excell, it will work correctly with built-in filters ( only text part of link will be used for filtering )
http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=3344&ssr=yes&s=filter%20link%20excell

In common case you can place a custom input in header and call grid.filterBy from some key event  or use native #text_filter and onFitlerStart event as

grid.attachEvent("onFilterStart",function(ord,data){
            //for simplicity , code below will change logic only of first text_filter in the grid
            var origianal=data[0];
            data[0]=function(value){
                          if (value.toString().replace(/<[^>]*>/,"").indexOf(original)!=-1) return true;
                         return false;
            }
          grid.filterBy(ord,data);
          return false;
});

above code replace static value with filtering function, which will remove any tags from value , before checking

Answer posted by JOR on Dec 12, 2008 08:32
I went with the onFilterStart method and it worked perfect thanks!  ...and significantly faster than the version I ended up working out.