Sorting using DbGrid with ClientDataSet

0

I'm using a DbGrid together with a DataSource. And I want to do the ordering as the customer clicks on the title. I made the following settings: In my Dbgrid in the DataSource property linkei my DS. In my Ds in the DataSet property I linkei my ClientDataSet. In the ClientDataset in the fields editor I added a field:

Name:cod_produto 
Type: Integer
Field type: Data

I have a search button, in it I make the query in a tbQuery.

My question is how do I load this data from TbQuery into my ClientDataSet so that it appears in DbGrid.

    
asked by anonymous 13.06.2016 / 21:07

3 answers

0

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

    
02.07.2016 / 04:22
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 procedure of conculta put a number that receives these columns:

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

After this, just put it in the query by order.

ibCLI001.SQL.Add('ORDER BY ' + pOrdem);
    
15.07.2016 / 16:03
0

Make a while in your table by giving an append to your ClientDataSet.

    while not tbQuery.eof do
    begin
      ClientDataSet.Append;
      ClientDataSet.FiedByName('NomeDoCampo').AsString :=
      tbQuery.FieldByName('NomeDoCampo').AsString; 
      ClientDataSet.Post;
      tbQuery.Next;
    end;
    
20.06.2016 / 20:53