:: Forum >>

Search Grid Function

I have a function that searches a grid for text and when it finds the text highlights the Row.

However how do I set the focus to this row?? Because if the dataset has a lot of Rows that forces scroll bars and the function finds the text at the bottom of the grid, its leaving the focus at the top of the Grid and I would like the focus to jump to the Row where it has found the text it was searching for...??

Please help

var SearchBox = new AW.UI.Input;
SearchBox.setStyle("Width","250px");
        
var Search = new AW.UI.Button;
Search.setStyle('width','100px');
Search.setControlText('Search');

Search.onControlClicked = function(event){
var searchText = SearchBox.getControlText();
if(searchText=='') return false;
for(var r=0;r<grd.getRowCount();r++)
{
for(var c=0;c<grd.getRowCount();c++)
{
var cellContent=grd.getCellText(c,r);
var pos=cellContent.indexOf(searchText);
if(pos !=-1)
{
grd.setSelectionMode("single-row");
grd.setSelectedRows([r]);
grd.setCurrentRow(r);
grd.setScrollTop(r);
}
}
}
}
Jez
Tuesday, March 16, 2010
Search.onControlClicked = function(event){
var searchText = SearchBox.getControlText();
if(searchText=='') return false;
for(var r=0;r<grd.getRowCount();r++)
{
for(var c=0;c<grd.getColumnCount();c++)
{
var cellContent=grd.getCellText(c,r);
var pos=cellContent.indexOf(searchText);
}
if(pos !=-1) break;
}

if(pos !=-1)
{
grd.setSelectionMode("single-row");
grd.setSelectedRows([r]);
grd.setCurrentRow(r);
//grd.setScrollTop( r * grd.getRowHeight()); /// can be used instead of set CurrentRow
}
}
Thursday, March 18, 2010
Thanks for the advice... that helped.

Here's the final code... That loops through and confirms whether to continue, because if it finds more than one occurrence it just keeps looping...

Search.onControlClicked = function(event){
var searchText = SearchBox.getControlText();
if(searchText=='') return false;
for(var r=0;r<grd.getRowCount();r++)
{
for(var c=0;c<grd.getRowCount();c++)
{
var cellContent=grd.getCellText(c,r);
var pos=cellContent.indexOf(searchText);
if(pos !=-1)
{
var desc = grd.getCellText(1,r);
grd.setSelectionMode(\"single-row\");
grd.setSelectedRows([r]);
grd.setCurrentRow(r);
grd.setScrollTop( r * grd.getRowHeight());
if (confirm('Found : '+searchText+' '+desc+' Continue Searching?'))
{
grd.setSelectionMode(\"single-row\");
grd.setSelectedRows([r]);
grd.setCurrentRow(r);
grd.setScrollTop( r * grd.getRowHeight());
} else {return false;}
}
}
}
}
Jez
Friday, March 19, 2010

This topic is archived.


Back to support forum

Forum search