Jump to content

Set TUniDBGrid's Column Width with percentage


Recommended Posts

Hi,

 

Most of the time when using css+html, width's are set by percentage like %80, %100. We need that on uniDBGrid's Column's with too because when browser's size changed columns are set still and we can't use all the space we have.

 

 

Thanks.

Link to post
Share on other sites

It has already been posted several times how to autowidth columns, I made a helper function

procedure UniDBGridAutoWidth(aGrid: TUniDBGrid; aFieldName: string = '');
var
  s: string;
  i: Integer;
begin
  if aFieldName = '' then
    s := 'sender.headerCt.forceFit=true;'
  else with TStringList.Create do try
    Delimiter := ';';
    StrictDelimiter := True;
    DelimitedText := LowerCase(aFieldName);
    for i := 0 to Pred(aGrid.Columns.Count) do
      if IndexOf(LowerCase(aGrid.Columns[i].FieldName)) <> -1 then
        s := s + Format('columns[%d].flex=1;', [i]);
  finally
    Free;
  end;

  if s <> '' then
    aGrid.ClientEvents.ExtEvents.Add(Format(
      'beforereconfigure=function beforereconfigure(sender, store, columns, oldStore, the, eOpts)' +
      '{%s}', [s])
    );
end;

Pass a field name to autowidth, or several field names separated with ';'.

If you don't pass any fields, all of them will have autowidth relating to their width set in designer.

  • Upvote 3
Link to post
Share on other sites

Thanks but I don't look for a solution, this topic is for featured and this is just a request. Why i have to do extra coding just to make a column width auto? If this is a web-framework it has to support web interface. This is better for uniGUI.

 

Best

Link to post
Share on other sites
  • Administrators

Why i have to do extra coding just to make a column width auto? If this is a web-framework it has to support web interface.

 

 

Well, in all other web frameworks you can't do anything useful without "lots of extra coding". uniGUI hides lots of these details for you and internally implements the code.

If you try to code directly in Ext JS or similar almost all of such details must be coded manually.

Link to post
Share on other sites

Well, in all other web frameworks you can't do anything useful without "lots of extra coding". uniGUI hides lots of these details for you and internally implements the code.

If you try to code directly in Ext JS or similar almost all of such details must be coded manually.

 

Of course, every framework, component packages etc. has much more detail after front-end but some functions/methods or properties are used by developers all the time like this issue ""Column Width". These common interfaces are valuable for a component library such as uniGUI.

 

I am not try to offend or discredit here, i am try to make this framework better.

 

best

Link to post
Share on other sites
  • 6 months later...

It has already been posted several times how to autowidth columns, I made a helper function

procedure UniDBGridAutoWidth(aGrid: TUniDBGrid; aFieldName: string = '');
var
  s: string;
  i: Integer;
begin
  if aFieldName = '' then
    s := 'sender.headerCt.forceFit=true;'
  else with TStringList.Create do try
    Delimiter := ';';
    StrictDelimiter := True;
    DelimitedText := LowerCase(aFieldName);
    for i := 0 to Pred(aGrid.Columns.Count) do
      if IndexOf(LowerCase(aGrid.Columns[i].FieldName)) <> -1 then
        s := s + Format('columns[%d].flex=1;', [i]);
  finally
    Free;
  end;

  if s <> '' then
    aGrid.ClientEvents.ExtEvents.Add(Format(
      'beforereconfigure=function beforereconfigure(sender, store, columns, oldStore, the, eOpts)' +
      '{%s}', [s])
    );
end;

Pass a field name to autowidth, or several field names separated with ';'.

If you don't pass any fields, all of them will have autowidth relating to their width set in designer.

hi

this solution not worked in Grouped UniDBGrid.

thanks.

Link to post
Share on other sites
  • 3 weeks later...
×
×
  • Create New...