CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Enabling/disabling button in a cell of a grid depending on a

by MarcoRu » 09 Jun 2017 11:10

Hi all, I check on the forum but I didn't find anything about this topic. Is possible enabling/disabling (or better hide or show) a button in a cell depending on a value of another cell? I have a Grid with GridProvider set to Cells_Provider. The columns are added dinamically. The last column is added in this way (with a cfgControl):

Code: Select all
col := gridCreaLotti.JQGridOptions.ColModel.Add;
    col.Formatter := gcfControl;
    col.FormatOptionsControl.ControlTemplate := IWRegionButton;
    col.Idx := 'CustomColumn';
    col.Name := 'Creazione lotto';
    col.OnUpdateControl := TIWCGJQGridOptionsColModelUpdateControl;
    col.Caption := 'Creazione lotto';
    col.Sortable := false;


Code: Select all
procedure TframeLotto.TIWCGJQGridOptionsColModelUpdateControl(Sender: TObject; ACol: TIWCGJQGridCol;
  const ARowId, ACellValue: string);
begin
  btnCreaLotoGrid.Tag := gridCreaLotti.RowIndexForRowId[ARowId];
  if (Pos('SCART', UpperCase(gridCreaLotti.JQGridProviderCells.Cell[0, gridCreaLotti.RowIndexForRowId[ARowId]].Value)
    ) > 0) then
    btnCreaLotoGrid.Tag := 999;
end;


and the result is this

Immagine.png


There is a way to hide/show the button if the value of the first cell on the same row is "Scarto"?
Hope someone can help me :)
You do not have the required permissions to view the files attached to this post.
MarcoRu
 
Posts: 41
Joined: 23 Sep 2014 16:39

by Jorge Sousa » 09 Jun 2017 11:25

Di you tried with

btnCreaLotoGrid.Visible:= false;

at

Code: Select all
if (Pos('SCART', UpperCase(gridCreaLotti.JQGridProviderCells.Cell[0, gridCreaLotti.RowIndexForRowId[ARowId]].Value)
    ) > 0) then
begin
    btnCreaLotoGrid.Tag := 999;
    btnCreaLotoGrid.Visible:= false;
end;
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by MarcoRu » 09 Jun 2017 11:55

Hi Jorge, yes I did,
the result is this
Immagine2.png


All buttons are set to visible = false, even if the condition enters only once :cry:

P.S.: the button is on a region
You do not have the required permissions to view the files attached to this post.
MarcoRu
 
Posts: 41
Joined: 23 Sep 2014 16:39

by Jorge Sousa » 09 Jun 2017 11:59

Hi

Can you please use

FormatOptionsControl.CreateCellsOnlRender = True
and
Col.OnUpdateCellControl

instead, like discussed @

https://www.cgdevtools.com/cgforum/viewtopic.php?f=34&t=809&p=3513&hilit=OnUpdatecontrol#p3513
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by MarcoRu » 09 Jun 2017 13:53

Hi , I tried your suggestion.

I set these parameters on column
Code: Select all
col := gridCreaLotti.JQGridOptions.ColModel.Add;
    col.Formatter := gcfControl;
    col.FormatOptionsControl.ControlTemplate := IWRegionButton;
    col.FormatOptionsControl.CreateCellsOnRender := true;
    col.Idx := 'CustomColumn';
    col.Name := 'Creazione lotto';
    // col.OnUpdateControl := TIWCGJQGridOptionsColModelUpdateControl;
    col.OnUpdateCellControl := TIWCGJQGridOptionsColModelUpdateCellControl;
    col.Caption := 'Creazione lotto';
    col.Sortable := false;


Thi is my OnUpdateCellControl event
Code: Select all
procedure TframeLotto.TIWCGJQGridOptionsColModelUpdateCellControl(Sender: TObject; ACol: TIWCGJQGridCol;
  AControl: TControl; ARowIdx: Integer; const ARowId, ACellValue: string; var AResizeCell: Boolean);
var
  Button: TIWCGJQButton;
begin
  try
    Button := gridCreaLotti.FindCellControl(btnCreaLotoGrid.Name, ACol.Index, ARowIdx) as TIWCGJQButton;
    if Assigned(Button) then
    begin
      Button.Tag := ARowIdx;
      if (Pos('SCART', UpperCase(gridCreaLotti.JQGridProviderCells.Cell[0, gridCreaLotti.RowIndexForRowId[ARowId]]
        .Value)) > 0) then
      begin
        Button.Tag := 999;
        Button.Visible := false;
      end
      else
        Button.Visible := true;
    end;
  except

  end;
end;


From debug all sems works fine, but wher i open it in browser i have this:
Immagine3.png

all buttons are invisible :shock:
You do not have the required permissions to view the files attached to this post.
MarcoRu
 
Posts: 41
Joined: 23 Sep 2014 16:39

by Jorge Sousa » 09 Jun 2017 14:25

Hi Marco

Please send me a test case, it's impossible for us to guess what is going on, and we've not a structure that allows to design a demo for every forum question. t.i.a.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by MarcoRu » 09 Jun 2017 15:53

Hi, thi is a test case. I cut my project. The code is in uFrameLotto frame. the version of CGdevTools are 2.3.0.69.

Best regards
You do not have the required permissions to view the files attached to this post.
MarcoRu
 
Posts: 41
Joined: 23 Sep 2014 16:39

by Jorge Sousa » 09 Jun 2017 16:36

hi again Marco

Set gridCreaLotti.RenderInvisibleControls = True

Maybe this also the problem with the previous method, using OnUpdateCell and CreateCellsOnRender = False
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by MarcoRu » 12 Jun 2017 09:24

Hi, I tried but didn't work
MarcoRu
 
Posts: 41
Joined: 23 Sep 2014 16:39

by assapan » 12 Jun 2017 11:16

Bonjiorno Marco,
I checked your sample project and modified it to make the button work .

1) set back
Code: Select all
 col.OnUpdateControl := TIWCGJQGridOptionsColModelUpdateControl;

2) modify
Code: Select all
procedure TframeLotto.TIWCGJQGridOptionsColModelUpdateControl(Sender: TObject; ACol: TIWCGJQGridCol;
  const ARowId, ACellValue: string);
var
  Button: TIWCGJQButton;
begin
  // Button := gridCreaLotti.FindCellControl(btnCreaLotoGrid.Name, ACol.Index, 1) as TIWCGJQButton;
  btnCreaLotoGrid.Tag := gridCreaLotti.RowIndexForRowId[ARowId];
/* added*/    btnCreaLotoGrid.Visible:=true;
  if (Pos('SCART', UpperCase(gridCreaLotti.JQGridProviderCells.Cell[0, gridCreaLotti.RowIndexForRowId[ARowId]].Value)
    ) > 0) then
  begin
    btnCreaLotoGrid.Tag := 999;
/*added*/    btnCreaLotoGrid.Visible:=False;
  end;
end;


your frame is created twice so when the first time it is created the button is set to visible = false when 'SCART' is found so when second frame is created button is not visible anymore so you have to force it to visible again , one thing you must understand is that a copy of main component is done after the call to UpdateControl so means that all the modifications on control is applyied to next calls.

Hope i helped
Want to visit Ardeche http://leclosdelarc.fr/index.php
The Pont d’Arc Cavern http://en.cavernedupontdarc.fr
Image
User avatar
assapan
 
Posts: 600
Joined: 16 Dec 2013 12:04
Location: France

Next

Return to JQGrid

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.