#1 2016-09-29 23:29:07

igors233
Member
Registered: 2012-09-10
Posts: 234

Client side custom field in TSQLTable/TSQLTableJSON

I would like to add RecNo (1 to number of records) field to TSQLTableJSON before displaying it in TSQLTableToGrid.
TSQLTableJSON content is taken from server with TSQLRecord.CreateAndFillPrepare/FillPrepare it has several fields and I would like to add calculated/custom RecNo field as first one, so final result would be something like:

RecNo       Field1        Field2
---------------------------------
1           Value11       Value12
2           Value21       Value22
3           Value31       Value32
...

underlying TSQLRecord is something like:

  TSQLSomeRec = class(TSQLRecord)
  private
    FField1: RawUTF8;
    FField2: RawUTF8;
  published
    property Field1: RawUTF8 index 5 read FField1 write FField1;
    property Field2: RawUTF8 index 10 read FField2 write FField2;
  end;

What is the prefered/mORMot way of doing something like this?

Offline

#2 2016-09-30 07:57:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Client side custom field in TSQLTable/TSQLTableJSON

Isn't it the already existing ID field?
Or an explicit increasing number?

Offline

#3 2016-10-03 00:06:59

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Client side custom field in TSQLTable/TSQLTableJSON

ab wrote:

Isn't it the already existing ID field?
Or an explicit increasing number?

Sorry for late reply, field doesn't exists in the table, it's not ID. It should be a new client side only field (I need it for displaying and printing) and it's values should go from 1 to number of records (so auto increasing).

Offline

#4 2016-10-03 13:20:26

Junior/RO
Member
Registered: 2011-05-13
Posts: 207

Re: Client side custom field in TSQLTable/TSQLTableJSON

Like a TTable.RecNo?

Offline

#5 2016-10-03 14:22:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Client side custom field in TSQLTable/TSQLTableJSON

So the TSQLTableJSON needs to be modified once loaded, or the JSON could simply be modified before affecting it to the TSQLTableJSON.

I guess using TDocVariant is a very easy way of adding such a field values, before filling TSQLTableJSON.

Offline

#6 2016-10-03 17:23:17

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: Client side custom field in TSQLTable/TSQLTableJSON

> So the TSQLTableJSON needs to be modified once loaded, or the JSON could simply be modified before affecting it to the TSQLTableJSON.
> I guess using TDocVariant is a very easy way of adding such a field values, before filling TSQLTableJSON.

Thanks, I was hoping there's some better way to avoid double processing of json dataset.
I'll try first to make TSQLTableJSON descendant and see if it's possible to make inplace changes.

On a general note, I think that TSQLTable would benefit of adding some easy to use calculated fields, like we have in standard TDataset.

Offline

#7 2016-10-03 20:17:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Client side custom field in TSQLTable/TSQLTableJSON

Yes, it is on the todo-list, but we don't need it here so it has a low priority...

Offline

Board footer

Powered by FluxBB