Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 02-05-2008
Avatar de totote
totote totote is offline
Miembro
 
Registrado: oct 2006
Posts: 150
Poder: 18
totote Va por buen camino
Talking Ordenar datos en un DBGrid con click en cabecera

Bueno como vi que en la parte de trucos no funcionaba para componentes de dbExpress, le pregunte a google y me respondio XD.
Este código pertenece al siguiente sitio

Código que realiza el ordenamiento:
Código Delphi [-]
unit f_Varios;

interface

uses
      TypInfo, DBClient, DB;

function SortCustomClientDataSet(DataSet: TClientDataSet;const FieldName: String): Boolean;

implementation

function SortCustomClientDataSet(DataSet: TClientDataSet;const FieldName: String): Boolean;
var
  i: Integer;
  IndexDefs: TIndexDefs;
  IndexName: String;
  IndexOptions: TIndexOptions;
begin
  Result := False;
  if IsPublishedProp(DataSet, 'IndexDefs') then
    IndexDefs := GetObjectProp(DataSet, 'IndexDefs') as TIndexDefs
  else
    Exit;

  if IsPublishedProp(DataSet, 'IndexName') then
    IndexName := GetStrProp(DataSet, 'IndexName')
  else
    Exit;

  IndexDefs.Update;
  if DataSet.Fields.FindField(FieldName) = nil then Exit;
  if IndexName = FieldName + '__IdxA' then
  begin
    IndexName := FieldName + '__IdxD';
    IndexOptions := [ixDescending];
  end
  else
  begin
    IndexName := FieldName + '__IdxA';
    IndexOptions := [];
  end;
  for i := 0 to Pred(IndexDefs.Count) do
  begin
    if IndexDefs[i].Name = IndexName then
    begin
      Result := True;
      Break
    end; //if
  end; // for
  if not Result then
  begin
    DataSet.AddIndex(IndexName, FieldName,IndexOptions);
    Result := True;
  end; // if not
  SetStrProp(DataSet, 'IndexName', IndexName);
end;

Código para utilizar el ordenamiento:

Código Delphi [-]
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  inherited;
  SortCustomClientDataset(ClientDataSet1,Column.FieldName);
end;


Saludos
__________________
¡Oh nooo! no compartas, compartir es pirateria, compartir te llevara a la carcel - Revolution OS
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ordenar un DBGrid con click sobre un campo bustio OOP 3 27-11-2007 19:00:41
Ordenar Datos en DBGrid mediante un Click anghell77 Varios 2 20-05-2006 17:59:27
Stringgrid Ordenar datos con click en titulo de columna dmassive Varios 1 20-01-2006 04:09:12
Como ordenar un DBGrid haciendo click sobre cada campo judoboy OOP 5 02-08-2005 02:52:31
ordenar datos del DBGrid! kage_01 Tablas planas 1 02-07-2005 03:42:28


La franja horaria es GMT +2. Ahora son las 17:53:37.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi