TTMSFNCDataGridDatabaseAdapter.LoadMode Property
Controls how many records are buffered and who sorts, filters, and groups. Default is
almBuffered.
API unit family: TMSFNCDataGridDatabaseAdapter
Declaring type: TTMSFNCDataGridDatabaseAdapter
Inherited from: TTMSFNCCustomDataGridDatabaseAdapter
Type: TTMSFNCDataGridDatabaseAdapterLoadMode
Syntax
property LoadMode: TTMSFNCDataGridDatabaseAdapterLoadMode;
__property TTMSFNCDataGridDatabaseAdapterLoadMode LoadMode = {read=FLoadMode, write=SetLoadMode, default=0};
Default: almBuffered
Remarks
almBuffered buffers only the records of the visible rows (or the current page when paging is on), which suits large datasets. Sorting is passed to the dataset: an index on the first sorted column is created for client datasets, FireDAC datasets, and the product's own custom dataset, while other datasets need OnSortData. Filtering is translated into TDataSet.Filter. Grouping is not available.
almAllRecords buffers every record so the grid sorts, filters, and groups the data itself; filtering is still passed to the dataset when DetailControl is used.
Changing the value reloads the grid.
Usage examples
Combine buffered loading, field conversion, and display overrides
Configure a database adapter for a large dataset while formatting stored values and overriding the rendered text per cell.
procedure TForm1.FormCreate(Sender: TObject);
begin
Adapter.DataGrid := Grid;
Adapter.DataSource := DataSource1;
Adapter.AutoCreateColumns := True;
Adapter.LoadMode := almBuffered;
Adapter.DynamicRecordCount := True;
Adapter.OnFieldToData := AdapterFieldToData;
Grid.OnGetCellDisplayValue := GridGetCellDisplayValue;
FDQuery1.Active := True;
end;
procedure TForm1.AdapterFieldToData(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord; AMasterField, AField: TField;
var ACellValue: TTMSFNCDataGridCellValue; var Handled: Boolean);
begin
if AField.FieldName = 'Amount' then
begin
ACellValue := FormatCurr('#,##0.00', AField.AsCurrency);
Handled := True;
end;
end;
procedure TForm1.GridGetCellDisplayValue(Sender: TObject;
ACell: TTMSFNCDataGridCellCoord; AData: TTMSFNCDataGridCellValue;
var AValue: string);
begin
if (ACell.Row > 0) and (ACell.Column = StatusColumn) then
AValue := '<b>' + AValue + '</b>';
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Grid->Adapter = Adapter; // the adapter is attached from the grid side
Adapter->DataSource = DataSource1;
Adapter->AutoCreateColumns = true;
Adapter->LoadMode = almBuffered;
Adapter->DynamicRecordCount = true;
Adapter->OnFieldToData = AdapterFieldToData;
Grid->OnGetCellDisplayValue = GridGetCellDisplayValue;
FDQuery1->Active = true;
}
void __fastcall TForm1::AdapterFieldToData(TObject *Sender,
const TTMSFNCDataGridCellCoord &ACell, TField *AMasterField, TField *AField,
TTMSFNCDataGridCellValue &ACellValue, bool &Handled)
{
if (AField->FieldName == "Amount")
{
ACellValue = TValue::From<System::UnicodeString>(FormatCurr("#,##0.00", AField->AsCurrency));
Handled = true;
}
}
void __fastcall TForm1::GridGetCellDisplayValue(TObject *Sender,
const TTMSFNCDataGridCellCoord &ACell, const TTMSFNCDataGridCellValue &AData,
System::UnicodeString &AValue)
{
TTMSFNCDataGridCellCoord Cell = ACell; // ACell is const; its getters are not
if ((Cell.Row > 0) && (Cell.Column == StatusColumn))
AValue = "<b>" + AValue + "</b>";
}