M.Ammar Posted August 4, 2021 Share Posted August 4, 2021 Hi I am Trying to save user selection in a multi selection Grid, and then restore the selection again to the grid. because after posting some values in the table the selection will be no longer available. Best regards. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 5, 2021 Share Posted August 5, 2021 20 hours ago, M.Ammar said: because after posting some values in the table the selection will be no longer available. Hello, Do you mean an insert operation, or also an edit? Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 5, 2021 Author Share Posted August 5, 2021 4 hours ago, Sherzod said: Hello, Do you mean an insert operation, or also an edit? Hi No Insert Operation in this Form, All Edit but I post values to the data source Via Looping Selected Rows try FDQry.DisableControls; for I := 0 to UniDBGridList.SelectedRows.Count - 1 do begin FDQry.Bookmark := UniDBGridList.SelectedRows[I]; FDQry.Edit; FDQrydeedTyName.AsString := UniCBDeedTyName.Text; FDQry.Post; end; finally FDQry.EnableControls; UniDBGridList.Refresh; end; so It Causes the selection to be at the last Selected Row after refreshing Grid Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 9, 2021 Author Share Posted August 9, 2021 Hi Sherzod I found one old topic that you have provided a solution and it is working but I have 2 issues procedure TfrmReptTransactionManagment.RestoreSelection(); var DBGridJSName: string; I: Integer; begin DBGridJSName := UniDBGridList.JSName; for I := 0 to SelectionList.Count - 1 do begin DBGridJSName := UniDBGridList.JSName; UniSession.AddJS(DBGridJSName + '.getSelectionModel().select(' + DBGridJSName + '.getStore().data.indexOfKey(' + SelectionList[I] + '), true)'); end; end; 1- calling this restore directly after the post action don't work I think because the grid in refresh, I had to use a button to call it after the post, is there is another way to call it after the grid refreshed? 2- I need to unselect any other selected rows before restoring the selection. Regards Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 9, 2021 Author Share Posted August 9, 2021 what dose option dgPersistentSelection do? Quote Link to comment Share on other sites More sharing options...
mhmda Posted August 9, 2021 Share Posted August 9, 2021 hi Quote Link to comment Share on other sites More sharing options...
Tokay Posted August 9, 2021 Share Posted August 9, 2021 2 hours ago, M.Ammar said: what dose option dgPersistentSelection do? You can look at the code, it can happens in the two places: if not (dgPersistentSelection in FOptions) then FBookmarks.Clear; 1 Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 9, 2021 Author Share Posted August 9, 2021 3 hours ago, mhmda said: This is a client-side code and it happens after loading data 😉 thank you mohamed for your help procedure TfrmReptTransactionManagment.UniDBGridListAjaxEvent( Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = 'load' then RestoreSelection(); end; it correctly call the restore procedure as you expected, but for some reason it is not working, but if I called by UniButton it works and I restore all selections. regards Quote Link to comment Share on other sites More sharing options...
mhmda Posted August 9, 2021 Share Posted August 9, 2021 Easy, then call your button from the js code (at load event as shown in picture like this:) MainForm.mybutton.fireEvent('click',MainForm.mybutton); Remember for security issue the button should be visible otherwise it will not work (at design time) in order to hide it @ runtime then use UniEvents->beforeInit and set hidden to true: function beforeInit(sender, config) { config.hidden=true; } OR Put your button on UniHiddenPanel 🙂 Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 10, 2021 Author Share Posted August 10, 2021 17 hours ago, mhmda said: Easy, then call your button from the js code (at load event as shown in picture like this:) MainForm.mybutton.fireEvent('click',MainForm.mybutton); Remember for security issue the button should be visible otherwise it will not work (at design time) in order to hide it @ runtime then use UniEvents->beforeInit and set hidden to true: function beforeInit(sender, config) { config.hidden=true; } OR Put your button on UniHiddenPanel 🙂 thanks again for your help I am learning a lot from you 🙂 it has the same outcome, I noticed that the selection is resorted successfully in the grid but it is not visibly selected, if edited again all old selection is modified correctly, the only issue is that only one selection is Visible I Modified one of the demos to explain. first select more than one record then click edit button , change category and click again you will see the issue GridMultiSelect - Checkbox.rar Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 10, 2021 Share Posted August 10, 2021 3 hours ago, M.Ammar said: GridMultiSelect - Checkbox.rar 3.11 MB · 1 download function store.load(sender, records, successful, operation, eOpts) { Ext.defer(function() { ajaxRequest(sender, '_load', []) }, 20); } procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_load' then RestoreSelection end; 1 Quote Link to comment Share on other sites More sharing options...
M.Ammar Posted August 10, 2021 Author Share Posted August 10, 2021 39 minutes ago, Sherzod said: function store.load(sender, records, successful, operation, eOpts) { Ext.defer(function() { ajaxRequest(sender, '_load', []) }, 20); } procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin if EventName = '_load' then RestoreSelection end; I really don't know how to thanks you enough for this one 1 Quote Link to comment Share on other sites More sharing options...
mhmda Posted August 10, 2021 Share Posted August 10, 2021 You can send me PM 🙂 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.