Jump to content

Set UniDBGrid filter value in code


abiery_iqms

Recommended Posts

Hi everyone,

 

Is it possible to set filter values on a TUniDBGrid at run-time using code?  If so, could you please give me a simple example?  I tried doing this, but it doesn't appear to do anything.  I also need to fire the OnColumnFilter event after I set the value.

 

The reason I am doing this is to restrore the state of the grid when a user enters a filter value, it needs to be remembered the next time the user opens the grid.  Is this something you can use the ExtJS stateId property with? http://docs.sencha.com/extjs/6.0.1/classic/Ext.grid.Panel.html 

procedure TIQWebInternalDBGrid.RestoreSavedFilters;
var
  i : integer;
begin
  if not IsDataSetActive then
    Exit;

  for i := 0 to Columns.Count - 1 do
    begin
      if Columns[i].Filtering.Enabled then
      begin
        if IsFilterable(Columns[i].Field, 'A' {Columns[i].Filtering.VarValue}) then
        begin
          Columns[i].Filtering.PrevValue := 'triggertheevent';
          Columns[i].Filtering.VarValue  := 'A';
        end;
      end;
    end;
end;

Thanks in advance!

Link to comment
Share on other sites

i do what you want to do. for this i save filter value in database.

 

For restore value in filter:

GridAO.Columns[j].Filtering.VarValue:=getSavedFilterValueForColumn(i);

 

And Afterrestore i call a procedure for apply filter value to dataset (see http://forums.unigui.com/index.php?/topic/9283-sorting-filtering-issue/&do=findComment&comment=47993 )

This procedure is also call in oncolumnfilter but i fired oncolumnfilter only when the filter is changed by user

Link to comment
Share on other sites

 

i do what you want to do. for this i save filter value in database.

 

For restore value in filter:

GridAO.Columns[j].Filtering.VarValue:=getSavedFilterValueForColumn(i);

 

And Afterrestore i call a procedure for apply filter value to dataset (see http://forums.unigui.com/index.php?/topic/9283-sorting-filtering-issue/&do=findComment&comment=47993 )

This procedure is also call in oncolumnfilter but i fired oncolumnfilter only when the filter is changed by user

 

I've gotten one step further in this process, and my filters are getting stored and restored.  However, simply setting the VarValue isn't getting the values back in to the filter TUniEdits.  Does that have to be done manually by setting the text property?


Link to comment
Share on other sites

I've gotten one step further in this process - storing/restoring filter values is working by using the VarValue, and by moving the filtering code outside of the event handler and simply calling it in two places.  The last part is the values are not displaying in the TUniEdits above each column.  When I inspect the fields while debugging they do indicate they have values in them when VarValue is updated - is this simply a UniSession.Synchronize issue?  I apologize if I'm asking foolish questions - it just doesn't seem to be quite working yet.

Link to comment
Share on other sites

Thank you, delagoutte.  I've attached a modified GridFiltering-2 project.  Simply replace the one in your C:\Program Files (x86)\FMSoft\Framework\uniGUI\Demos\Desktop with this.  I've only modified the Main.pas.  It is also worth mentioning that I am on uniGUI 1.0.0.1414, could this be a bug?  I've also uploaded a teamviewer recording of the problem.

GridFiltering-2.zip

Recording_of_problem.zip

Link to comment
Share on other sites

The resolution here was to move the restoration of the filter values to the "OnReady" ExtEvent. 

 

Steps:

In the ClientEvents => ExtEvents on the TUniDBGrid, I added a beforerender event listener

1.  Added onbeforerenderenvent:

function beforerender(sender, eOpts)
{
  ajaxRequest(sender, "OnReady",[]);
}
 

2. On the TUniDBGrid OnAjaxEvent handler, added the following code:

 
procedure TIQWebDBGrid.UniFrameAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if CompareText(EventName, 'OnReady') = 0 then
  begin
    if RememberColumnFilters then
      Grid.RestoreSavedFilters;
  end;
end;

I hope this is a help to somebody.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...