学习unigui【18】unidbgrid的GridsGroupingSorting
折腾二天,你不按照demo里的代码来,就是没有效果。功力不够导致的。学习学习再学习!努力努力再努力!
procedure TUniGridsGroupingSorting.UniDBGrid1MultiColumnSort( Columns: TUniDBGridColumnArr; Directions: TUniSortDirections); var OrderStr : string; I : Integer; begin UniMainModule.ADOQuery5.Close;//必须在UniMainModule OrderStr := 'select * from [Customers]' + ' order by '; for I := Low(Columns) to High(Columns) do begin OrderStr := OrderStr + '['+Columns[I].FieldName+ '] '+IfThen(Directions[I], 'ASC', 'DESC')+','; end; OrderStr := RemoveTrailingChar(OrderStr, ','); UniMainModule.ADOQuery5.SQL.Text := OrderStr; UniMainModule.ADOQuery5.Open; end;
其二、点击列排序:
procedure TUniGridsColumnSort.SortColumn(const FieldName: string; Dir: Boolean); begin if Dir then ClientDataSet1.IndexName := FieldName+'_index_asc' else ClientDataSet1.IndexName := FieldName+'_index_des'; end; procedure TUniGridsColumnSort.UniDBGrid1ColumnSort(Column: TUniDBGridColumn; Direction: Boolean); begin SortColumn(Column.FieldName, Direction);//必须分开写调用 end;
看明白没,必须按这种格式,分开写。否则就是不行。作者没有说明why?再WEB中这处理的理由,你知道WHY?
实际上非常简单:
1、创建内存表TFDMemTable
procedure TUniForm_SelectAPanient.UniFormCreate(Sender: TObject); var i : Integer; begin UniMainModule.fdqry_QueryPatient.Open('select * from patient_info'); //符合条件的患者资料 fdmtbl_QueryPatient.CopyDataSet(UniMainModule.fdqry_QueryPatient, [coStructure, coRestart, coAppend]); fdmtbl_QueryPatient.Filter := ''; fdmtbl_QueryPatient.IndexesActive := True; UniMainModule.fdqry_QueryPatient.Close; end;
2、改变index
procedure TUniForm_SelectAPanient.undbgrd1MultiColumnSort( Columns: TUniDBGridColumnArr; Directions: TUniSortDirections); var i : integer; OrderStr : string; begin OrderStr := ''; for I := Low(Columns) to High(Columns) do begin OrderStr := OrderStr + Columns[I].FieldName+ IfThen(Directions[I], ':A', ':D')+';'; end; Delete(OrderStr, Length(OrderStr), 1); fdmtbl_QueryPatient.IndexFieldNames := OrderStr; end;
good luck!