关闭

Grid中的排序功能

273人阅读 评论(0) 收藏 举报
 procedure DBGridSort(FSortColumn: TColumnEh;out pbASC:boolean);
var
  OldIndex: string;
begin
//  if (FSortColumn.Grid.DataSource = nil) then Exit;
//  if not (FSortColumn.Grid.DataSource.DataSet.Active) then Exit;
  OldIndex := TClientDataset(FSortColumn.Grid.DataSource.DataSet).IndexName;
  if OldIndex <> '' then
  begin
    TClientDataset(FSortColumn.Grid.DataSource.DataSet).IndexName := '';
    TClientDataset(FSortColumn.Grid.DataSource.DataSet).DeleteIndex(OldIndex);
  end;
  case pbASC of
    True:
      begin
        if FSortColumn.Field.FieldKind = fkLookUp then
          TClientDataset(FSortColumn.Grid.DataSource.DataSet).AddIndex('px', FSortColumn.Field.KeyFields, [ixDescending]) //已经是升序就按降序排列
        else if FSortColumn.Field.FieldKind = fkData then
          TClientDataset(FSortColumn.Grid.DataSource.DataSet).AddIndex('px', FSortColumn.Field.FieldName, [ixDescending]);
      end;
  else //否则按升序排列
    begin
      if FSortColumn.Field.FieldKind = fkLookUp then
        TClientDataset(FSortColumn.Grid.DataSource.DataSet).AddIndex('px', FSortColumn.Field.KeyFields, [ixPrimary])
      else if FSortColumn.Field.FieldKind = fkData then
        TClientDataset(FSortColumn.Grid.DataSource.DataSet).AddIndex('px', FSortColumn.Field.FieldName, [ixPrimary]);
    end;
  end; {end case}
  TClientDataset(FSortColumn.Grid.DataSource.DataSet).IndexName := 'px';
  pbASC := not pbASC;
end;
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9272次
    • 积分:219
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:6篇
    • 译文:0篇
    • 评论:1条
    文章存档
    最新评论