« Return to Thread: Adding a filterer to FilteringTable widget

Re: Adding a filterer to FilteringTable widget

by Tom Trenka :: Rate this Message:

Reply to Author | View in Thread

Whoops, my apologies.  It actually passes your filter function the value of the field for that particular column; I need to change the docs for that, thank you for the catch.

You can optimize that function a little like so:

function inspectRow(val){
    if (!val) return true;
    var filtText = document.myFilter.namefilter.value.toLowerCase();
    if (filtText) {
        return (val.toLowerCase().indexOf(filtText) >= 0);
   }
   return true;
}


trt

Malaney J. Hill wrote:
Wow, the filtering table is amazing!!  I was able to cobble together a
filter without much
problem.  I basically tied the "applyFilters" call to the onkeyup of a
textbox and specified a filter as you indicated.  (Autocomplete="off"
helps big time).  Here's my filter code, though know it is definitely
not optimized and doesn't deal with numeric values .... yet:

===============
function inspectRow(rowObj)
{
    if (!rowObj) return true;
    var filtText = document.myFilter.namefilter.value.toLowerCase();
    if (filtText)
    {
        var rObj = rowObj.toLowerCase();
        if (rObj.indexOf(filtText) >= 0)
        {
                return true;
        }
        else
        {
                return false;
        }
   }
   else
   {
        return true;
   }
}

After getting this working, I wanted to try to filter more than one
row at a time.  It was at this point that I realized I had to call a
seperate function to do this.  It would be really nice to be able to
send parameters to the filter function.  This way I don't have to
specify the filter input within the function itself.  Could there
possibly already be a way to pass parameters to the filter call?

Another minor detail is that you said that my filter would receive an
HTML Row as input when in fact it receives the data contained in the
column (i.e. Adam, David, etc ...).  This is actually much easier to
parse than a row so I vote you keep it as is.

Other than that, FilteringTable is definitely a marvelous piece of code.

Bravo,

Malaney

On 8/15/06, Tom Trenka <dojo-interest@dept-z.com> wrote:
>
> Right now, there aren't.  But that's a relatively new piece of functionality,
> and I need to add that as a part of the test suite at some point.
>
> But here's the basics of it:  a filter function return a boolean value, true
> if it satisfies your condition, and false if it doesn't.  A custom filtering
> function should take an HTML Row as the argument, which you can inspect in
> any way you see fit.
>
> When you've written your filtering function, there are several ways of
> adding it to the widget:
>
> 1. in the column in question, like so:
>
> <th field="myField" filterusing="myFilterFunction">my field</th>
>
> Note that this is a reference (i.e. no parenthesis).
>
> 2. using [widget].setFilter:
>
> dojo.widget.byId("myTable").setFilter("myField", myFilterFunction);
>
> And to perform the filtering:
>
> dojo.widget.byId("myTable").applyFilters();
>
> This is all pretty new and it might change based on usage (so feedback is
> encouraged), but I think the API is pretty stable now.
>
> trt
>
>
> Malaney J. Hill wrote:
> >
> > Hello,
> >
> > I'm wondering if there are any examples available of adding filterers
> > to the FilteringTable widget.  I'd like to be able to show/hide rows on
> > based on input received via text box.
> >
> > Thanks,
> >
> > MJH
> > _______________________________________________
> > Dojo FAQ: http://dojo.jot.com/FAQ
> > Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
> > Dojo-interest@dojotoolkit.org
> > http://dojotoolkit.org/mailman/listinfo/dojo-interest
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Adding-a-filterer-to-FilteringTable-widget-tf2110294.html#a5821097
> Sent from the Dojo forum at Nabble.com.
>
> _______________________________________________
> Dojo FAQ: http://dojo.jot.com/FAQ
> Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
> Dojo-interest@dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-interest
>
_______________________________________________
Dojo FAQ: http://dojo.jot.com/FAQ
Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
Dojo-interest@dojotoolkit.org
http://dojotoolkit.org/mailman/listinfo/dojo-interest

 « Return to Thread: Adding a filterer to FilteringTable widget