abiery_iqms Posted October 16, 2017 Share Posted October 16, 2017 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 More sharing options...
Sherzod Posted October 17, 2017 Share Posted October 17, 2017 Hi, Also, you can try to use this approach: ... TUniControl(UniDBGrid1.Columns[I].Filtering.Editor).JSInterface.JSCode('var me='#1'; me.fireEvent("change", me);'); ... Best regards, Link to comment Share on other sites More sharing options...
delagoutte Posted October 17, 2017 Share Posted October 17, 2017 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 More sharing options...
delagoutte Posted October 17, 2017 Share Posted October 17, 2017 also , if you fire event on each setting column filter, it is not very good. it is better to set all value and after applyfilter Link to comment Share on other sites More sharing options...
Sherzod Posted October 17, 2017 Share Posted October 17, 2017 also , if you fire event on each setting column filter, it is not very good. it is better to set all value and after applyfilter Yes, this is correct Link to comment Share on other sites More sharing options...
abiery_iqms Posted October 17, 2017 Author Share Posted October 17, 2017 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 More sharing options...
abiery_iqms Posted October 17, 2017 Author Share Posted October 17, 2017 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 More sharing options...
delagoutte Posted October 18, 2017 Share Posted October 18, 2017 I do'nt use UniSession.Synchronize issue for filtering. Could you do a simple test case with your problem ? Link to comment Share on other sites More sharing options...
abiery_iqms Posted October 18, 2017 Author Share Posted October 18, 2017 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 More sharing options...
abiery_iqms Posted October 18, 2017 Author Share Posted October 18, 2017 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 More sharing options...
delagoutte Posted October 19, 2017 Share Posted October 19, 2017 ok thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now