lfgarrido Posted October 13, 2016 Share Posted October 13, 2016 Hello Guys, I'm testing uniGUI Trial version, I would like to know how can I sort each columns of a Desktop UniDbGrid. I tried to follow GridColumnSort demo that is ClientDataSet, but I'm using FireDac. So at MainForm I did: //OnColumnSort event procedure TMainForm.UniDBGrid1ColumnSort(Column: TUniDBGridColumn; Direction: Boolean); begin UniMainModule.SortColumn(Column.FieldName, Direction); end; And at MainModule: uses DB, DBClient; procedure TUniMainModule.SortColumn(const FieldName: string; Dir: Boolean); begin if Dir then Main.MainForm.FDQuery1.IndexName := FieldName+'_ASC' else Main.MainForm.FDQuery1.IndexName := FieldName+'_DSC'; end; procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject); var I: Integer; IndexnameAsc : string; IndexnameDes : string; begin with Main.MainForm.FDQuery1 do begin for i := 0 to FieldCount-1 do begin IndexnameAsc := Fields.FieldName+'_ASC'; IndexnameDes := Fields.FieldName+'_DSC'; IndexDefs.Add(IndexnameAsc, Fields.FieldName, []); IndexDefs.Add(IndexnameDes, Fields.FieldName, [ixDescending]); end; end; end; But when I click at column title nothing happens What I miss? Tks Quote Link to comment Share on other sites More sharing options...
Emerson Posted October 13, 2016 Share Posted October 13, 2016 procedure TFrameModelo.UniDBGrid1ColumnSort(Column: TUniDBGridColumn; Direction: Boolean); begin if Direction then TFdquery(DsPes.DataSet).IndexName := Column.FieldName+'_index_asc' else TFdquery(DsPes.DataSet).IndexName := Column.FieldName+'_index_des'; end; procedure TFrameModelo.UniFrameCreate(Sender: TObject); var I: Integer; IndexnameAsc : string; IndexnameDes : string; begin if Assigned(DsPes.DataSet) then begin // TFDQuery(DsPes.DataSet).IndexDefs.Clear; for I := 0 to TFDQuery(DsPes.DataSet).FieldCount-1 do begin IndexnameAsc := TFDQuery(DsPes.DataSet).Fields[I].FieldName+'_index_asc'; IndexnameDes := TFDQuery(DsPes.DataSet).Fields[I].FieldName+'_index_des'; if TFDQuery(DsPes.DataSet).Indexes.FindIndex(IndexnameAsc) = nil then begin with TFDQuery(DsPes.DataSet).Indexes.Add do begin Name := IndexnameAsc; Fields := TFDQuery(DsPes.DataSet).Fields[I].FieldName; Active := True; end; end; if TFDQuery(DsPes.DataSet).Indexes.FindIndex(IndexnameDes) = nil then begin with TFDQuery(DsPes.DataSet).Indexes.Add do begin Name := IndexnameDes; Fields := TFDQuery(DsPes.DataSet).Fields[I].FieldName; Options := [soDescending]; Active := True; end; end; end; end; for I := 0 to UniDBGrid1.Columns.Count - 1 do UniDBGrid1.Columns[i].Sortable := True; end; try this code. 1 Quote Link to comment Share on other sites More sharing options...
lfgarrido Posted October 13, 2016 Author Share Posted October 13, 2016 Works like a charm, tks dude! 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.