#1 2015-05-29 08:59:27

noobies
Member
Registered: 2011-09-13
Posts: 139

Code to add hide drawgrid column

function TSQLTable.CalculateFieldLengthMean(var aResult: TIntegerDynArray;
  FromDisplay: boolean=false): integer;
...
    for R := 1 to fRowCount do // sum all lengths by field
      for F := 0 to FieldCount-1 do begin
        case fFieldType[F].ContentType of
...
          sftUnknown: aResult[F]:=0; //  I ADD THIS TO WORK HIDE COLUMN
...
  for F := 0 to FieldCount-1 do begin
    if aResult[F] = 0 then Continue; // IF 0 HIDE COLUMN, SOME TIMES NEED HIDE COLUMN
    n := cardinal(aResult[F]) div Tot; // Mean = total/count
    if n=0  then n := 1;  // none should be 0
    aResult[F] := n;
    inc(result,n); // fast calculate mean sum
  end;

i hide column to save space in grid, approvedate - green color in table, declinedate - red color in table, not need show 2 column

  tbl_patients := ClientRest.ExecuteList([], s);
  tbl_patients.SetFieldType('approvedate',sftUnknown);
  tbl_patients.SetFieldType('declinedate',sftUnknown);

or may be add new type sftNotVisible?

Last edited by noobies (2015-05-29 12:26:50)

Offline

#2 2015-05-29 20:20:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Code to add hide drawgrid column

Did you try TSQLTable.DeleteColumnValues() ?

Offline

#3 2015-06-01 06:05:39

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

I tried this function, but it's not what me need, especially as a function of the error if I specify the column in which the row 5 no data (for example, an empty string) function returns an error. (if all the rows have the data all works), though I do not understand why it can be necessary, because you can simply specify the column in the sql command.
I do not need to display an empty column without the data I need to hide a column.
i have wide monitor, but many users not have. User dont need last 2 column - color show approve or decline this record.
of course table show in auto resize

  with TSQLTableToGrid.Create(dgList, tbl_Patients, ClientRest) do begin
    ShowHint := False;
    OnValueText := OnValueTextTablePatients;
    OnDrawCellBackground := OnDrawCellBackgroundPatients;
    Resize(nil);
    ...
  end;

before
7173077.jpg
after
7166933.jpg

Last edited by noobies (2015-06-01 06:20:14)

Offline

#4 2015-06-01 06:36:35

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

quick fix

procedure TSQLTable.DeleteColumnValues(Field: integer);
var i: integer;
    U: PPUTF8Char;
begin
  if cardinal(Field)>=cardinal(FieldCount) then
    exit; // out of range
  U := @fResults[Field+FieldCount];  // U^ = column UTF-8 content for this field
  for i := 1 to fRowCount do begin
    if U^ <> nil then U^[0] := #0; // just void UTF-8 content text   //ADD if U^ <> nil then 
    inc(U,FieldCount);
  end;
end;

yes it works - column hide but have no data and no color((( Need only hide column without erase data

i think add sftNotVisible best solution

Last edited by noobies (2015-06-01 06:37:44)

Offline

#5 2015-06-01 09:54:20

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

Offline

#6 2015-06-01 11:48:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Code to add hide drawgrid column

Offline

#7 2015-06-01 13:29:54

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

  TSQLFieldType = (
    sftUnknown, sftAnsiText, sftUTF8Text, sftEnumerate, sftSet,
    sftInteger, sftID, sftRecord, sftBoolean,
    sftFloat, sftDateTime, sftTimeLog, sftCurrency, sftObject,
    {$ifndef NOVARIANTS}
    sftVariant,
    {$endif}
    sftBlob, sftBlobDynArray, sftBlobCustom, sftUTF8Custom, sftMany,
    sftModTime, sftCreateTime, sftTID, sftRecordVersion, sftHidden); //<=== add sftHidden, and other constants too
function TSQLTable.CalculateFieldLengthMean(var aResult: TIntegerDynArray;
  FromDisplay: boolean=false): integer;
...
        case fFieldType[F].ContentType of
...
             sftHidden: aResult[F]:=0;
...
  for F := 0 to FieldCount-1 do begin
    if aResult[F] = 0 then Continue;
...

AB, can you add sftHidden to framework?

Offline

#8 2015-06-01 14:20:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Code to add hide drawgrid column

No, sftHidden has no place in there.
This is not a true kind of field, just some UI related trick.

Try to use TSQLTable.SetFieldLengthMean().

Offline

#9 2015-06-02 06:21:14

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

ab, sorry may be i slowpoke, but i dont understand how can i realize hidden columns by using TSQLTable.SetFieldLengthMean().
if write something like this:

  SetLength(len, tbl_patients.FieldCount - 1);
  for i := 0 to tbl_patients.FieldCount - 1 do len[i] := tbl_patients.FieldLengthMean(i);
  len[colAproove] := 0;
  len[colDecline] := 0;
  tbl_patients.SetFieldLengthMean(len);
  with TSQLTableToGrid.Create(dgList, tbl_Patients, ClientRest) do begin
    ShowHint := False;
    OnValueText := OnValueTextTablePatients;
    OnDrawCellBackground := OnDrawCellBackgroundPatients;
    Resize(nil);
...
   end;

it does not work, since resize run after this code, and all columns recalculated

P.S. i try use TSQLTableToGrid procedure, but procedure has different format and apply for all column(((

procedure TSQLTable.SetFieldLengthMean(const Lengths: array of cardinal);
...
procedure TSQLTableToGrid.SetFieldLengthMean(const Lengths: RawUTF8; aMarkAllowed: boolean);
...

Last edited by noobies (2015-06-02 06:25:22)

Offline

#10 2015-06-04 08:27:28

noobies
Member
Registered: 2011-09-13
Posts: 139

Re: Code to add hide drawgrid column

ab, i rewrite some code and delete sftHidden, and add only 2 line to work hide, please add this line to framework.

how use to hide column

  tblList.SetFieldType('approvedate', sftDateTime, nil, 0); //set ContentSize to 0
  tblList.SetFieldType('declinedate', sftDateTime, nil, 0); //set ContentSize to 0

changes

function TSQLTable.CalculateFieldLengthMean(var aResult: TIntegerDynArray;
  FromDisplay: boolean=false): integer;
...
        case fFieldType[F].ContentType of
...
        if fFieldType[F].ContentSize = 0  then aResult[F]:=0; // ADD THIS TO WORK
        inc(U); // points to next value
      end;
...
  for F := 0 to FieldCount-1 do begin
    if aResult[F] = 0 then Continue;  // ADD THIS TO WORK
...

Last edited by noobies (2015-06-04 08:28:05)

Offline

Board footer

Powered by FluxBB