Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Javed on Sep 07, 2008 09:43
open dhtmlx forum
filter grid with <form> element

Hi,

I am suing the grid filter function filterBy with the form element. I have implemented the filter funciton using dhtmlXGridFromTable and the table is populated from the database.
When I click on the button to fitler the table for given value, it scans the grids very quickly and then brings back the original values. When I remove the form element it works fine but i need the <FORM> to be there.

Please suggest what is the workaround for this.
Answer posted by Support on Sep 08, 2008 05:57
>>When I click on the button to fitler the table for given value, it scans the grids very quickly
It possible that clicking of the button triggers the form submit, which causes the issue in your case. ( the grid itself can't cause such behavior)

You can try to update code of button as

<input type="button" onclick="some_filter_call(); (arguments[0]||event).cancelBubble=true; " >
Answer posted by Javed on Sep 08, 2008 08:04
Thanks for sending me the answer, I have tried the scipts, but it did not change anything. It  does not filter by grid and I want to filter multiple rows by doing the following;

        // search by Org Type
myGrid.filterBy(0,document.getElementById("searchText").value);
         // search by Org Name
myGrid.filterBy(1,document.getElementById("searchText").value,true);
        // search by Org Acronym
myGrid.filterBy(2,document.getElementById("searchText").value,true);


It does not wrok, what I would like to do is, First I filter by Organization type, then filter the result further by organization name, or acronym, or the other way around.

Please suggest,

thanks for your help as usual.

Javed
Answer posted by Support on Sep 08, 2008 10:27

The filtering will  use AND logic for all used filters, so it will filter rows where 

type contains searchText AND name contains searchText AND acronym contains searchText

If you need to use OR logic, you need to use custom fuction as filter value.( works only in latest builds - please contact us directly at support@dhtmlx.com if you need an update )

var text = document.getElementById("searchText").value;
grid.filterBy(0,function(value,id){
      if  ( grid.cells(id,0).getValue().toString().toLowerCase().indexOf(text) != -1) return true;
      if  ( grid.cells(id,1).getValue().toString().toLowerCase().indexOf(text) != -1) return true;
      if  ( grid.cells(id,2).getValue().toString().toLowerCase().indexOf(text) != -1) return true;
      return false;
});