Swapping rows

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Atys
Posts: 16
Joined: Sun 15 Nov 2015 20:26

Swapping rows

Post by Atys » Tue 23 Feb 2016 12:05

Hi everyone,

What is the best/easiest way to swap records in a TUniQuery, CachedUpdates=True, without commiting
to the sql server and keeping the modified values in the dataset?
Like you would move a position in a list up/down, but commiting the changes only by the user.
The list is shown in a 3rd party dbgrid.

Thx

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Swapping rows

Post by azyk » Fri 26 Feb 2016 10:40

The question about how to swap records in grid is not related to UniDAC functionality, since the TUniQuery dataset can't manage visual controls behavior.

As a solution for the mentioned task, you can add a fake field into the SELECT query of the dataset, which will be responsible for record display order in the grid (SELECT ... , 0 as order_field). Specify this field name in the TUniQuery.IndexFieldNames property in order for the dataset to perform local sorting by this field. Set the TField.ReadOnly property of the field to False. And to swap records in the grid, modify the order_field field values for these records.

Atys
Posts: 16
Joined: Sun 15 Nov 2015 20:26

Re: Swapping rows

Post by Atys » Wed 07 Jun 2017 23:43

It has nothing to do with GUI.
The grid is just a reflection of the buffer.
You could expose ExchangePos or a similar function as public... there is no reason to hide this function.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Swapping rows

Post by azyk » Mon 12 Jun 2017 12:36

There is not the ExchangePos function in UniDAC - you can implement it by yourself using the proposed method or another one.

Post Reply