Web.UI ASP.NET Grid: Retrieve the filtered set of rows in Client RunningMode

Posted Thu Mar 19, 2009 @ 4:09 PM

Currently the Grid doesn't expose the filtered set of GridItems after a search/filter action, preventing operations from being applied exclusively to that set of rows. Until Grid provides a method to access these, you can build your own set of filtered items by using the undocumented gridLevel FilterExpression property.

eg.
JS:
function getFilteredRows(grid)
{
    var table = grid.get_table();
    var filteredRows = new Array();
    for (i=0;i<table.getRowCount();i++)
    {
      var DataItem = table.getRow(i);
      if (eval(grid.Levels[0]. F i l t e r E x p r e s s i o n ))
      {
        filteredRows[filteredRows.length] = DataItem;
      }
    }
    return filteredRows;
}
You could then grab the filtered items (after a search/filter action) with something like
JS:
 
// grab the first search result's text in column 3
alert(getFilteredRows(Grid1)[0].getMemberAt(3).get_text());
 

Note: You'll have to remove the spaces from the " F i l t e r E x p r e s s i o n " above, as our blog software doesn't permit this string in codeblocks.

Posted to Hwan Hong by hwan

Posted on Thu Mar 19, 2009 @ 4:09 PM

Filed under: ,