CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Looking for event that fires after grid is done rendering

General discussion

by ScottWGast » 16 Apr 2014 00:18

I would like to update a few label captions with things like "number of rows", "selected row count" _after_ the grid has finished rendering. The grid is using an adodataset that changes when a user clicks on various buttons. The grid paints just fine, but it seems that the values of .SelRows is not correct until the grid has completed rendering.

I've tried the grid.OnAfterRenderHTML, but when I check .SelRows, it returns the number of rows that were selected _before_ I refreshed the dataset.

Am I barking up the wrong tree?

Scott

UPDATE:
As it turns out, the only item that is not correct is the Grid.JQGridOptions.Caption. I set the caption to show the number of rows and the number of selected rows... _after_ I open the dataset. The number of rows is correct, but the number of "Selected rows" shows the number of rows that were selected before I closed the dataset, changed the parameters and the re-opened the dataset.

Also, based on criteria, I either show the columns "Sent Date", "Received Date" or both. (See LoadEmailGridData, below). These columns _always_ display, it doesn't matter if I set their .Viewable property to False.


Code: Select all
procedure TframeEmailClient.LoadEmailGridData;
var
  strSQL: String;
begin

  if UserSession.OpenDBConnection then
    begin
      if Self.adoEmailList.Active then
        Self.adoEmailList.Close;

      if Self.FSelectedFolderID = Self.FSentFolderID then
        begin
          strSQL := 'SELECT * FROM email WHERE folder_id = :FolderID ORDER BY sent_date DESC';
          Self.gridEmail.JQGridColumns.ItemsByName['sent_date'].Viewable := True;
          Self.gridEmail.JQGridColumns.ItemsByName['received_date'].Viewable := False;
        end
      else if Self.FSelectedFolderID = Self.FInboxFolderID then
        begin
          strSQL := 'SELECT * FROM email WHERE folder_id = :FolderID ORDER BY received_date DESC';
          Self.gridEmail.JQGridColumns.ItemsByName['sent_date'].Viewable := False;
          Self.gridEmail.JQGridColumns.ItemsByName['received_date'].Viewable := True;
        end
      else
        begin
          strSQL := 'SELECT * FROM email WHERE folder_id = :FolderID ORDER BY received_date DESC';
          Self.gridEmail.JQGridColumns.ItemsByName['sent_date'].Viewable := True;
          Self.gridEmail.JQGridColumns.ItemsByName['received_date'].Viewable := True;
        end;

       Self.adoEmailList.CommandText := strSQL;
      Self.adoEmailList.Parameters.ParamByName('FolderID').Value := Self.FSelectedFolderID;
      Self.adoEmailList.Open;

      if Self.adoEmailList.RecordCount > 400 then
        begin
          Self.gridEmail.JQGridOptions.RowNum := 250;
          Self.gridEmail.JQGridOptions.PagerVisible := True;
          Self.gridEmail.JQGridOptions.Scroll := False;
        end
      else
        begin
          Self.gridEmail.JQGridOptions.RowNum := Self.adoEmailList.RecordCount;
          Self.gridEmail.JQGridOptions.PagerVisible := False;
          Self.gridEmail.JQGridOptions.Scroll := True;
        end;

      Self.SetGridTitle();
    end;

end;

procedure TframeEmailClient.SetGridTitle(IsRowSelected: Boolean = True);
var
  strCaption: String;
  iCount: Integer;
begin
  strCaption := S2Snax.IntegerToString(Self.adoEmailList.RecordCount) + ' Email' + S2Snax.Iif(Self.adoEmailList.RecordCount>1,'s','') + ' (' + Self.FSelectedFolderName + ')';
  iCount := Length(Self.gridEmail.JQGridOptions.SelRows);

  if (iCount > 0) and IsRowSelected then
    strCaption := strCaption + ' (' + IntToStr(iCount) + ' Rows Selected)';

  Self.gridEmail.JQGridOptions.Caption := strCaption;

end;

ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by ScottWGast » 16 Apr 2014 18:55

bump
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by Jorge Sousa » 16 Apr 2014 19:02

Hi and Sorry for the delay

SelRows must be used for read

you have to use JQGridOptions.SetSelection in OnLoadComplete
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by ScottWGast » 17 Apr 2014 14:37

I have modified the code so both the SetMenuOptions and SetGridTitle procedures are called from Grid.JQGridOptions.OnLoadComplete:

Code: Select all

procedure TframeEmailClient.gridEmailJQGridOptionsLoadComplete(Sender: TObject; AParams: TStringList);
begin
  Self.SetMenuOptions;
  Self.SetGridTitle;
end;

procedure TframeEmailClient.SetMenuOptions;
var
  strCaption: String;
  i, iCount: Integer;
begin
  iCount := Length(Self.gridEmail.JQGridOptions.SelRows);
  // start at index "2" to bypass "Compose" and "Refresh"
  for i := 2 to Self.menuEmail.MenuItems.Count - 1 do
    Self.menuEmail.MenuItems[i].Visible := (iCount > 0);

  if Self.FSelectedFolderID = Self.FSpamFolderID then
    Self.menuEmail.MenuItems[C_MENU_SPAM].Visible := False;

  if (Self.FSelectedFolderID = Self.FTrashFolderID) or (Self.FSelectedFolderID = Self.FSpamFolderID) then
    Self.menuEmail.MenuItems[C_MENU_MOVE_TO_TRASH].Visible := False
  else
    Self.menuEmail.MenuItems[C_MENU_DELETE_FOREVER].Visible := False;

end;

procedure TframeEmailClient.SetGridTitle;
var
  strCaption: String;
  iCount: Integer;
begin
  strCaption := S2Snax.IntegerToString(Self.adoEmailList.RecordCount) + ' Email' + S2Snax.Iif(Self.adoEmailList.RecordCount>1,'s','') + ' (' + Self.FSelectedFolderName + ')';
  iCount := Length(Self.gridEmail.JQGridOptions.SelRows);

  if (iCount > 0) then
    strCaption := strCaption + ' (' + IntToStr(iCount) + ' Rows Selected)';

  Self.gridEmail.JQGridOptions.Caption := strCaption;

end;


It looks like Grid.JQGridOptions.SelRows is still returning the number of selected rows from the previous dataset.

How to I un-select the rows that are selected, or force SelRows to update?

Scott
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by Jorge Sousa » 17 Apr 2014 14:49

Hello

It looks like Grid.JQGridOptions.SelRows is still returning the number of selected rows from the previous dataset.


previous dataset?

How to I un-select the rows that are selected, or force SelRows to update?


To clear the selection, in the browser, there is a JQGridOptions method ClearSelection i think it's the name, but is well documented.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by ScottWGast » 17 Apr 2014 15:06

Previous dataset : when a user clicks on a panel item (depicting a folder image), the dataset that is bound to the grid is closed, and a new parameter value is set, then the dataset is opened. if there were rows selected before the panel item is clicked, the value of .SelRows is not updated to when the OnLoadComplete event fires, even though the newly updated grid does not show that any rows are "selected".

I cannot find .ClearSelection anywhere. I did find JQGridOptions.ClearGridData, but it is not working to clear the selection; I am calling .ClearGridData right after I close my dataset.
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02

by ScottWGast » 17 Apr 2014 15:45

OK, I found .JQGridOptions.ResetSelection

That works.

Scott
ScottWGast
 
Posts: 875
Joined: 23 May 2012 11:02


Return to General - Archive

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.