CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

OnSubGridBeforeExpand

Suggest new components/features

by jredoc » 25 Dec 2013 17:35

In a grid - subgrid scenario such as illustrated in the cgDevTools 2 demo, it would be helpful if the OnSubGridBeforExpand event contained a Cancel parameter which when set to True would prevent expansion of the subgrid.

A very simple example for the use of this parameter would be when subgrid records were only being viewed (i.e. no record insertion in the subgrid was allowed) and there were no subgrid records present. In this scenario, the subgrid expansion could be programmatically prevented by setting Cancel := True.

For this scenario I currently check the record count of the subgrid and; if there are no records, I execute a IWCGJQDialogEx which contains an OK button. The OnClick event of this button programmatically closes the subgrid.


Staying with this example, it would be useful if the user could be notified when a subgrid contained no record by simply looking at the parent grid. For example, if there were no subgrid records, the color of the "+" in the expand column could be set to a different color such as red.

TIA

John
jredoc
 
Posts: 125
Joined: 11 Jun 2013 03:34

by Jorge Sousa » 26 Dec 2013 12:02

Hi

you can define/change Grid.JQGridOptions.OnBeforeSelectRow.Script:= 'function(rowid,e) { if (rowid=="someid") return false; return true; }';

On JQGridOptions.OnLoadComplete
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by jredoc » 28 Dec 2013 17:15

I am confused (which seems to be my normal state anymore).

In the cgDevTools subgrid example and in my project, when the "+" in the parent grid is selected with the mouse, the events
IWCGJQGrid2.JQGridOptions.OnSubGridBeforeExpand and
IWCGJQGrid2.JQGridOptions.OnSubGridRowExpanded execute, but the event OnBeforeSelectRow does not execute. This applies irrespective of Grid.JQOptions.CellEdit := True or False. In my case the value is True;

In that the OnBeforeSelectRow event does not fire, I fail to see how I can get the Results of the function you propose? It apologize, but I just don't see the answer. Please elaborate.

TIA

John
jredoc
 
Posts: 125
Joined: 11 Jun 2013 03:34

by jredoc » 04 Jan 2014 03:52

I have revisited this topic to see what I was missing. The central question was how to obtain the record count of a subgrid prior to opening the subgrid and if the record count was zero: a) prevent the subgrid from opening and b) display a notification to the user of that effect.

Observations:
1) I misunderstood the outcome of the script given by support. I was thinking that the script returned a Boolean variable, but this made no sense to me. What the script actually does is prevent the execution of the event if the script returns a Boolean False.

2) I correctly stated that pressing the "+" button does not execute the OnBeforeSelectRow event, and that both of the following events DO execute.
- IWCGJQGrid2.JQGridOptions.OnSubGridBeforeExpand and
- IWCGJQGrid2.JQGridOptions.OnSubGridRowExpanded

The answer to the question involves two parts:
a) getting a count of the subgrid records from the OnSubGridBeforeExpand event and display a message if there are no records.
b) implementing the script provided by support in the OnSubGridRowExpanded event to prevent display of the grid.
To accomplish the two steps above the following 3 code snippets were implemented.

Snippet 1
with IWCGJQGrid2.JQGridOptions.OnSubGridBeforeExpand do
begin
with BrowserParams.Add do
begin
BrowserScript:= 'rowid'; // OnSubGridBeforeExpand.Arguments
ServerName:= 'RowID';
end;

OnEvent := Grid2BeforeExpandSubGrid;
end;


Snippet 2
procedure TIWCGFrame_MedQuest.Grid2BeforeExpandSubGrid(Sender: TObject; AParams: TStringList);
begin
with UserSession.AdsTablePtMedHxAns2 do
begin
Active := False;
Filtered := False;
Filter := '(UniquePtNumber = ' + IntToStr(UserSession.tempUniquePtNumber) + ') and ' +
'(PrimaryQuestion = False) and ' +
'(System = ' + '"' + UserSession.tempSelectedMedHxSystem + '"' + ') and ' +
'(Link_Index = ' + IntToStr(StrToInt(tempExpandedRowID)) + ')';
Filtered := True;
Active := True;

tempSubgridRecordCount := RecordCount;
if RecordCount >= 1 then
begin
if tempExpandedRowID <> AParams.Values['RowID'] then
begin
IWCGJQGrid2.JQGridOptions.CollapseSubGridRow(tempExpandedRowID);
end;
end
else
begin
DisplayPostNotification;
end;
end;
end;


Snippet 3
procedure TIWCGFrame_MedQuest.DisplayPostNotification;
var
iButtom: TIWCGJQCustomDialogButton;
begin
ResetDialog;

// This is a label placed on the IWCGJQDialog1
IWLabelDialog1.Caption := 'There are no supplemental questions associated with the selected Medical-Dental Q&A question.';

with IWCGJQDialogEx1 do
begin
JQDialogOptions.Title:= 'Medical Conditions Changed?';
JQDialogOptions.Modal:= True;
JQDialogOptions.Buttons.Clear;
iButtom:= JQDialogOptions.Buttons.Add;
iButtom.Text:= 'Close Subgrid';
iButtom.OnClick.OnEvent := OnClickPostTableEvent;
Visible := True;
end;
IWCGJQDialogEx1.AjaxReRender(False, False); // ** The second parameter must be False
end;


I hope this helps somebody


John
jredoc
 
Posts: 125
Joined: 11 Jun 2013 03:34


Return to Suggestions

Who is online

Users browsing this forum: No registered users and 2 guests

Contact Us.