Ultra Grid - How to test if a filter has been set

Posted by MGreenwood on 14-Mar-2011 06:57

Hi does anyone know if there is a way to see if a filter is set on the ultragrid?

We have coded our grid so that if after a filter is applied the user starts a new search they are asked of they want to keep the filter. If they say "No" the filters are cleared, if yes no action is taken. So this only fires if/when a filter is added.

The users have asked to be prompted to keep or clear filters if a filter exists.

Thanks

All Replies

Posted by kopfb on 14-Mar-2011 08:02

You could try checking one of the following to see if there are any rows filtered.

NameofYourGrid:Rows:GetFilteredOutNonGroupByRows()

NameofYourGrid:Rows:GetFilteredInNonGroupByRows()

Brad

Posted by MGreenwood on 14-Mar-2011 10:18

Hi Brad,

Thanks for the suggestion but. . .   I dont know how to implement this.

I have defined a variable

DEFINE VARIABLE uRowsCollection_FilteredInRows AS Infragistics.Win.UltraWinGrid.RowsCollection NO-UNDO.

and I can assign the  GridSpecialOffers:Rows:GetFilteredInNonGroupByRows() to it

but still can't work out how to get something useful from it.

What am I missing ?

Posted by kopfb on 14-Mar-2011 10:39

Hi Michael,

Are you using the built in filtering of the UltraWinGrid? If so then the simplest way (The guru's may have a better solution) to check if the grid has been filtered is to check the

FilteredInRowCount of the grid. So for example:

IF SomeGridName:Rows:FilteredInRowCount > 0  THEN DO: /* Grid has been filtered */

       /* Ask message to clear filter. */

      

MESSAGE "Filter has been applied. Do you want to clear the filtering? VIEW-AS ALERT-BOX QUESTION

       BUTTONS YES-NO

       UPDATE lClearFilter AS LOGICAL.

     

       IF lClearFilter THEN /* User answered yes to clear filter row */

            SomeGridName:Rows:ColumnFilters:ClearAllFilters().

END.

Do this help?

Thanks,

Brad

  

 

Posted by kopfb on 14-Mar-2011 11:03

Hi Michael,

Another way may be to loop through each cell in the filter row and see if there is data in that row:

DEFINE VARIABLE iCount AS Integer NO-UNDO.

DEFINE VARIABLE fRow AS Infragistics.Win.UltraWinGrid.UltraGridRow NO-UNDO.

fRow = SomeGridName:Rows:FilterRow.

DO iCount = 0 TO fRow:Cells:Count - 1:

    IF fRow:Cells[iCount]:Text > "" THEN DO:

        MESSAGE "Clear Filter?"

        VIEW-AS ALERT-BOX QUESTION

        BUTTONS YES-NO

        UPDATE lClear AS LOGICAL.

        IF lClear THEN

            Grid_Rackinv:Rows:ColumnFilters:ClearAllFilters().

    END.

END.

These are just someways to check this. There may be better ways to do this.

Brad

Posted by MGreenwood on 14-Mar-2011 11:31

Hi Brad,

So close but . .

Yes we are using the built in filtering of the grid.

The screen we have developed has some  initial selection criteria (product code, date etc) and a search button.  Click the search button and we get a results set back with lots of columns which the users can  filter on.  What the users don't want to happen is, they go off to do something and when they come back to do a new seach they "forget" a filter has been applied and so items are filtered out and they don't see them.

This method would be fine if there was always something filtered IN, but you could have a  filter on a column which is out of view, change the search criteria and if nothing matches the filter everything would be filtered out. Sadly there isn't a  "FilteredOutRowCount".

Ideally there would be a way of saying you have applied filters to columns "this", "that" and "the other"  do you want to keep them.

Hmmm we dont have a filtered out but the equivalent might be to compare filtered in with the row count.

YES  By Jove we've got it.

Thanks Brad

  This seems to work given the scenario above, i.e. if everything is filtered out.
    IF MyGrid:Rows:FilteredInRowCount
        NE MyGrid:Rows:Count THEN
    DO:
      IF MessageBox:QUESTION(
             "Filters have been applied to this grid.",
             "Would you like to clear them?  " ) THEN
        ClearAllColumnFilters().
    END.
Of course it doesn't detect a scenario where there's a filtered and  everything is Filtered In !

Posted by kopfb on 14-Mar-2011 11:39

Hi Michael,

You could theoretically use the looping code above and check to see if there is filetered data in the cell. If there is data then get the column name, stored that is a string (Char) variable get the next cell with data, stored that in the same variable  and then give the user a message with all the columns that have filtered data in them. Just a thought.

Good luck!

Brad

Posted by Tung on 05-Nov-2012 08:27

In case anyone's interested, I've managed to use GetFilteredInNonGroupByRows() so I can activate the first visible filtered row.

DEFINE VARIABLE oRow      AS UltraGridRow NO-UNDO.
DEFINE VARIABLE oRowArray AS UltraGridRow NO-UNDO EXTENT.

EXTENT(oRowArray) = grJob:Rows:FilteredInRowCount.
oRowArray = grJob:Rows:GetFilteredInNonGroupByRows().
oRow = oRowArray[1] NO-ERROR.
IF VALID-OBJECT(oRow) THEN
grJob:ActiveRow = oRow.

This thread is closed