Jump to content

uniDBGrid: Save Multi Selection and restore it


M.Ammar

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

3 hours ago, mhmda said:

image.png.489c98d7e6ef7ee7836668472b99378c.png

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 

Link to comment
Share on other sites

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 🙂

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

 

  • Like 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...