Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TIWGrid - Can't use percentage widths and heights



Permlink Replies: 3 - Last Post: Feb 19, 2018 2:38 AM Last Post By: Alberto Pilat
Alberto Pilat

Posts: 6
Registered: 4/10/00
TIWGrid - Can't use percentage widths and heights
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2018 3:25 AM
Hi,
we are currently migrating our web applications from Intraweb 12.2.35 to Intraweb 14.2.6 and we have noticed a different behavior in the TIWGrid component between the two versions of IW.

The TIWGridCell class holds two properties, "Width" and "Height", both String types. In IW 12 we could specify any value in any measure unit, for example '20px', '20%', '20em', and so on. The property values were just appended in the HTML as
the <td> element "width" or "height" attribute - or as CSS property in the inline "style" attribute.

In IW 14 this seems not to be possible anymore because when the grid is rendered a 'px' suffix is always appended at the end of "width" and "height" properties value. If the cell width is set to '20px', it becomes '20pxpx'; if it is '20%' it becomes
'20%px' and so on. The browser detects these values as invalid and automatically ignores them.

We tried configuring TIWGrid and TIWGridCell in different ways, with no luck.
Then we gave a look to IW 14.2.6 source code and we found in the IWCompGrids unit the method TIWGridCell.RenderSelf(). Inside we found the following lines of code that seem to be the cause of this behavior:

LStyle := '';
if not Wrap then begin
  LStyle := LStyle + 'white-space: nowrap; ';
end;
if (Width <> '') and (Width <> '0') then begin
  LStyle := LStyle + 'width: ' + Width + 'px; ';
end;
if (Height <> '') and (Height <> '0') then begin
  LStyle := LStyle + 'height: ' + Height + 'px; ';
end;
if BGColor <> clNone then begin
  LStyle := LStyle + 'background-color: ' + ColorToRGBString(BGColor) + '; ';
end;


We have a lot of pages where we need to set cells width in percentage, so this 'px' suffix is causing troubles...
How can we resolve this issue?

This is a code snippet that can be used to reproduce the problem (GridPercWidth is an instance of TIWGrid):

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
var
  i,j:Integer;
begin
  // Grid with width percentage.
  // This fails because 'px' is appended to the CSS 'width'.
  for i := 0 to GridPercWidth.RowCount - 1 do
  begin
    for j := 0 to GridPercWidth.ColumnCount - 1 do
    begin
      GridPercWidth.Cell[i,j].Text:=Format('Cell[%d,%d]',[i,j]);
      GridPercWidth.Cell[i,j].Width:='25%'; // will be rendered as '25%px' !
    end;
  end;
end; 


Thanks in advance.
Marco Gallizio
Alberto Pilat

PS: we can provide a full test project if you need one. Just tell us how to submit it to you.

Alberto Pilat

Posts: 6
Registered: 4/10/00
Re: TIWGrid - Can't use percentage widths and heights
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2018 12:35 AM   in response to: Alberto Pilat in response to: Alberto Pilat
Hi,
is there any news regarding this question?

Thanks in advance.
Marco Gallizio
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: TIWGrid - Can't use percentage widths and heights
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2018 1:42 AM   in response to: Alberto Pilat in response to: Alberto Pilat
If you have a test project ready, please submit it to alexandre [at] atozed dot com

I'll have a look.

These changes were introduced when IW started rendering HTML5 pages and got rid of quirks mode which is still the way IW 12 renders its pages. I think it is not difficult to fix/adapt it to your needs, though.

Kind regards
Alberto Pilat

Posts: 6
Registered: 4/10/00
Re: TIWGrid - Can't use percentage widths and heights
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 19, 2018 2:36 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Ok, I sent to you a small example project right now.
Thank you.
Marco Gallizio
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02