Sorting using Dbgrid with Clientdataset

Asked

Viewed 710 times

0

I’m using a Dbgrid along with a Datasource. And I’m willing to do the ordering as the client clicks on the title. I made the following settings: On my Dbgrid on the Datasource property I inked my DS. At my Ds on the Dataset property I inked my Clientdataset. In Clientdataset in Fields editor I added a field:

Name:cod_produto 
Type: Integer
Field type: Data

I have a boot to fetch, in it I make the consultation in a tbQuery.

My doubt is how I play this Tbquery data into my Clientdataset, so it appears in Dbgrid.

3 answers

1

Go to the onTitleClick event and put:

if xOrdemAsc then
   RefazSQL(Column.FieldName + ' ASC')
else
   RefazSQL(Column.FieldName + ' DESC');

DBGrid1.OnDblClick := Nil;

in the conculta process put a variable that receives these columns:

procedure TfCLI001.RefazSQL(pOrdem : String = 'NOME ASC');

after that just put in the order by of the query.

ibCLI001.SQL.Add('ORDER BY ' + pOrdem);

0


You can use a DataSetProvider connected to the TBQuery, and in the estate "Providername" of the ClientDataset refer to it. Before the search, close the CDS, reopening it after the search. The data will be there.

0

Do a while on your table by giving an append on your Clientdataset.

    while not tbQuery.eof do
    begin
      ClientDataSet.Append;
      ClientDataSet.FiedByName('NomeDoCampo').AsString :=
      tbQuery.FieldByName('NomeDoCampo').AsString; 
      ClientDataSet.Post;
      tbQuery.Next;
    end;
  • I thought I’d do it that way, I just wanted to know if there’s any method that would return it to me, I tried the method MoveBy(-1), but it didn’t work out.

  • You can use the Datasetprovider component linked to your Dataset, in this case your Query. Datasetprovider will transfer data from Query to Clientdataset dynamically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.