Reputation: 386
When clicking on the title column header, TcxGridDBtableView
automatically groups by that column. I don't want that, I want to order by that column.
I want it to be grouped by that column when accessed by menu (TcxGridPopupMenu
-> Goup by this column).
Upvotes: 1
Views: 2904
Reputation: 1328
As @Uli Gerhardt mentioned, your desired behavior is what a TcxDBGridTableView
will do out of the box. You must have changed the behavior, possibly altering the view's
OptionsCustomize.GroupBySorting
This will enable exactly what you describe. From the DevExpress help:
Specifies whether sorting data by a column results in grouping by this column.
Syntax
property GroupBySorting: Boolean;
Description Enabling the GroupBySorting option allows you to emulate the behavior of MS Outlook 2003. This implies that clicking a column header results in grouping data by the clicked column's values. The previously applied grouping is cleared in such cases. If the GroupBySorting option is disabled, clicking a column header results in sorting data by this column's values.
Note that the GroupBySorting option has no effect if sorting via code.
The default value of the GroupBySorting property is False.
Upvotes: 1
Reputation: 30715
In the code below, SetUpGrid
cancels any grouping already set up on a cxGridDBTableView,
enables column sorting and sorts the view on a Name column.
The Groupby1Click
method groups/ungroups on a given column in code, by setting its GroupingIndex (see Online Help).
procedure TDevexGroupingForm.SetUpGrid;
var
i : Integer;
begin
try
cxGrid1DBTableView1.BeginUpdate;
// Hide GroupBy panel
cxGrid1DBTableView1.OptionsView.GroupByBox := False;
// Allow column sorting
cxGrid1DBTableView1.OptionsCustomize.ColumnSorting := True;
// Undo any existing grouping e.g. set up in IDE
for i:= 0 to cxGrid1DBTableView1.ColumnCount - 1 do begin
cxGrid1DBTableView1.Columns[i].GroupIndex := -1;
end;
// Sort TableView on Name column. Needs 'Uses dxCore'
cxGrid1DBTableView1Name.SortOrder := soAscending;
finally
cxGrid1DBTableView1.EndUpdate;
end;
end;
procedure TDevexGroupingForm.Groupby1Click(Sender: TObject);
var
ACol : TcxGridDBColumn;
Index : Integer;
begin
// The following code operates on the focused column of a TcxGridDBTableView
// If the view is already grouped by that column, it is ungrouped;
// Otherwise, the column is added to the (initially empty) list of columns
// by which the view is grouped;
Index := TcxGridTableController(cxGrid1DBTableView1.DataController.Controller).FocusedColumnIndex;
if Index < 0 then
exit;
ACol := cxGrid1DBTableView1.Columns[Index];
if ACol = Nil then
exit;
if ACol.GroupIndex < 0 then begin
// Add ACol to the list of grouped Columns
ACol.GroupIndex := cxGrid1DBTableView1.GroupedColumnCount + 1;
end
else begin
// Ungroup on ACol
ACol.GroupIndex := -1;
end;
end;
Upvotes: 1
Reputation: 2416
Just click on the header, and disable the properties what you do not need.
Upvotes: 0