:: Forum >>

Reset the row setStyle to allow a search in Grids

I have a grid that I am cycling through the rows looking for a searchterm...

BUT, I just want to highlight the rows... which means that searching for a different key means changing the external textbox and clicking the search button again.

So, here's my searching function.... how can I RESET the rows to their CSS alternating colors/backgrounds after this runs? (otherwise you have to completely redo the grid to get rid of any previous searches)

Button_Items_Search.onClick=function(){
        var searchText='';
        var found=false;
        var count=0;
        var searchText = [null,null,null];
        if(Input_Items_Search_UPC.getControlText().length>1) {
            searchText[0]= new RegExp(Input_Items_Search_UPC.getControlText().replace("\"","''"),"i");
        }
        if(Input_Items_Search_SKU.getControlText().length>1) {
            searchText[1]= new RegExp(Input_Items_Search_SKU.getControlText().replace("\"","''"),"i");
        }
        if(Input_Items_Search_Description.getControlText().length>1) {
            searchText[2]= new RegExp(Input_Items_Search_Description.getControlText().replace("\"","''"),"i");
        }

        for(var i=0; i<Grid_Items_Items.getRowCount(); i++) {
            for(var j=0; j<searchText.length; j++) {
                if(searchText[j]!=null) {
                    var tmp=Grid_Items_Items.getCellData(j,i);
                    if(searchText[j].test(tmp)) {
         Grid_Items_Items.getTemplate("row", i).setStyle("color", "white");
     Grid_Items_Items.getTemplate("row", i).setStyle("background", "blue");
                        found=true;
                        count++;
                    }
                }
            }
        }
        if(!found) alert('Not Found');
        else alert('Found '+count+' entries');
    }
John Mason
Wednesday, December 6, 2006
John,
I am trying to do the same thing. Any progress on this?
Joel
Friday, December 8, 2006
Well, my bad news is that it is easier to filter it and then restore if after filtering.... so here's what I did. And no, I still didn't get anywhere with the color "reset"....

Button_Items_Search.onClick=function(){
        var count;
        var searchText = new Array();
        var matchingRows = new Array();
        var currentSearchData = Data_Items_Items;

        if(Input_Items_Search_UPC.getControlText().length>0) {
            searchText.push([0,Input_Items_Search_UPC.getControlText().replace("\"","''")]);
        }
        if(Input_Items_Search_SKU.getControlText().length>0) {
            searchText.push([1,Input_Items_Search_SKU.getControlText().replace("\"","''")]);
        }
        if(Input_Items_Search_Description.getControlText().length>0) {
            searchText.push([2,Input_Items_Search_Description.getControlText().replace("\"","''")]);
        }

        for(var j=0; j<searchText.length; j++) {
            var nextSearchData = new Array();
            count=0;
            for(var i=0; i<currentSearchData.length; i++) {
                var searchTerm= new RegExp(searchText[j][1],"i");
                var tmp=currentSearchData[i][searchText[j][0]];
                if(searchTerm.test(tmp)) {
                    nextSearchData.push(currentSearchData[i]);
                    count++;
                }
            }
            currentSearchData = nextSearchData;
        }

        if(count==0) {
         Grid_Items_Items.setCellData(Data_Items_Items);
         Grid_Items_Items.setRowCount(Data_Items_Items.length);
            Grid_Items_Items.setRowIndices(getAllRowIndices(Data_Items_Items));
        } else {
         Grid_Items_Items.setCellData(currentSearchData);
         Grid_Items_Items.setRowCount(currentSearchData.length);
            Grid_Items_Items.setRowIndices(getAllRowIndices(currentSearchData));
        }
     Grid_Items_Items.refresh();
        Label_Data_Items_Items_Value.setControlText(Grid_Items_Items.getRowCount());
    }

John Mason
Friday, December 8, 2006
so you are refreshing the entire grid? is that correct? does that work faster than simply hiding rows that don't comply with your search? also, the refresh must be annoying - do you have large sets of data or are your tables small?
Joel
Friday, December 8, 2006
BTW - I see that we can easily add CSS Rules dynamically. I'm wondering if we can update them to be !important and then remove !important when needed. That might be a way of turning the CSS setting on and off?
Joel
Friday, December 8, 2006
John,

I figured it out. Set the css background to !important. Then when de-selecting rows:

obj.setRowSelected(rownum,false);
obj.setRowState("notselected",rownum);
Joel
Monday, December 11, 2006

This topic is archived.


Back to support forum

Forum search