Row id - identification on server
TreeGrid documentation
The rows must be somehow identified on server for
uploading changes to server and for
server paging.
The rows in TreeGrid are identified by
id attribute, this attribute is always sent to server in every request.
To be sure what id the rows have, you can define new id column <C Name='id'/>.
Setting row id attribute
This is the basic option. Set
id attribute of every row to unique string. By default this string can contain only letters and '_'. It can be changed by
IdChars.
New row will get new id generated from the same characters.
The new generated id is always the highest id in the grid.
If row has neither set its id nor generated according to IdNames, it automatically set to "R"+number from 1.
<I> string
id
Both letters lowercase!
Unique ID of the row.
Set it in input XML for every row. It can contain only characters defined in <Cfg
IdChars />.
For new rows it will be automatically generated from the characters defined in <Cfg
IdChars />.
The id attribute must not be changed by API.
<Cfg> string
IdChars
["_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]
Accepted characters when generating new id. In this order.
Example for the default setting: if the last id was "ab" the next id is "ac", for "az" is "b_", for "zzz" is "____".
<Cfg> int
NumberId
[0]
Set it to
1 for generating number ids. And set
IdChars = '0123456789'.
This attribute says, that the id cannot start with 0.
In fact, this attribute says, that id cannot start with count of NumberId characters from start of
IdChars.
The start from some higher number than 0 set
LastId attribute.
<Cfg> string
IdPrefix
This string is inserted before generated new id (before the last part).
In this case all ids in XML must contain this prefix.
<Cfg> string
IdPostfix
This string is appended at the end of generated new id.
In this case all ids in XML must contain this postfix.
<Cfg> string
LastId
Last (maximal) id when used
server paging or server child paging, to not generate duplicated ids on client.
Can be used only when IdNames contains only one item!
New generated id (of new added row) will get next id.
If
IdPrefix and / or
IdPostfix are used, the LastId attribute can, but need not contain them.
new 12.1 <Cfg> int
DuplicateId
[0]
What to do if two rows have the same id. Bit array.
1. bit | &1 |
For 0 it generates unique id of the actual row that's id is being set. Default behavior.
For 1 it generates unique id of the old row that collides with the new row.
Useful when changing more row ids by <Changes> tag and rows can get duplicate ids temporary.
|
2. bit | &2 | If set, does not show warning about duplicate row id. |
3. bit | &4 | If set, applies the DuplicateId also when loading data. |
upd 9.1 <I> string
NewId
New row id returned from server.
To change row id attribute from server you cannot set it directly, because the row will not be found, you need to set it to
NewId.
The server should return the new row id in save response in <Changes> tag like:
<Grid><Changes><I id='orig id' Changed='1' NewId='new id'/></Changes></Grid>
(Since 9.1) It is set also in uploaded data if the row id will be changed due IdNames or FullId settings. Only when set
Upload_Flags='NewId'
new 7.0 <Cfg> string
AutoIdPrefix
["AR"]
This string is inserted before every automatically generated id.
For every row without id is created unique number id from 1 with this prefix: AR1, AR2, AR3 ...
The number is increased for every row and is never restarted, except reloading whole grid by Reload method (but
not ReloadBody).
new 11.0 API variable int
AutoId
The automatically generated id that will be get by the next new row. Starts on 1 and is increased after any new row added.
Change it carefully to never generate duplicate ids.
new 7.0 <Cfg> string
GroupIdPrefix
["GR"]
This string is inserted before automatically generated id for group rows.
For every group row is created unique number id from 1 with this prefix: GR1, GR2, GR3 ... It is independent on AutoId for normal rows.
The id number is set back to 1 on every grouping change.
new 8.0 <Cfg> int
GroupIdValue
[0]
For
0 it creates the group row ids as
GroupIdPrefix + ascending number
For
1 it creates the group row ids as column name +
GroupIdPrefix + grouping value
For
2 it creates the group row ids as column name +
GroupIdPrefix + first child row id
For
3 it creates the group row ids as row Level +
GroupIdPrefix + grouping value
For
4 it creates the group row ids as row Level +
GroupIdPrefix + first child row id
new 7.0 <Cfg> string
ChildIdPrefix
["CR"]
This string is inserted before automatically generated id for child page rows (created by
MaxChildren attribute).
For every child page is created unique number id from 1 with this prefix: CR1, CR2, CR3 ... It is independent on AutoId for normal rows.
The number is increased for every child page and is never restarted, except reloading whole grid by Reload method (but not ReloadBody).
Row id in tree
In tree you can identify rows according to their parents by setting
FullId.
<Cfg> bool
FullId
[0]
If set to 1, row
id contains all its parent ids as id prefix, separated by '$'.
In input XML the ids can be full or only parts. If the id is only part, it is updated on load and for API it is always full.
If parent id is "R1" the input row id can be "R2" or "R1$R2", for upload and in API is the id always "R1$R2".
For example:
<I id='1'> <I id='1-1'/> <I id='1-2'><I id='1-2-1'/></I></I> will be replaced as full ids:
<I id='1'> <I id='1$1-1'/> <I id='1$1-2'><I id='1$1-2$1-2-1'/></I></I>. Or you can set it straight in the input XML.
If row is moved, the
id attribute is
not changed immediately, it is updated after server accept the changes.
upd 9.1 <I> string
NewId
New row id returned from server.
To change row id attribute from server you cannot set it directly, because the row will not be found, you need to set it to
NewId.
(Since 9.1) It is set also in uploaded data if the row id will be changed due IdNames or FullId settings. Only when set
Upload_Flags='NewId'
Using one or more (editable) columns as row identity
As row identity (like database primary key) you can use any row attributes or column names set to
IdNames.
If used editable columns as id source, the last attribute in IdNames is automatically updated to be the primary key always unique.
The row id attribute is generated from these attributes, so on upload and in API you can use this id attribute.
All the primary keys set in input XML must be unique!
The values in the last attribute from IdNames must contain only characters from IdChars or must be set AppendId='1'.
The row attribute id is changed only after server accepts changes, never on source attribute value change!
<Cfg> string[ ]
IdNames
["id"]
Comma separated list of attributes fully identifies the row, these attributes are like
unique primary key in database table.
The list can contain column names, attributes like
Def or any user defined row attribute, but must
not contain the
id attribute itself.
The row
id attribute is automatically created from the attribute values from the list, separated by '$'. If any value contains '$', it is replaced by '_'.
The
last attribute in list is specific, because its value is generated automatically for new rows from
IdChars,
IdPrefix and
IdPostfix.
If the list item is
editable column and its value is changed, there is possibility that the
id will
not be unique.
In this case the
last attribute value is re-generated (before changes are sent to server).
After changes are sent to server, the row
id is updated according to changed attribute (column) values.
Remember, after a user changes the source of id, the id attribute itself is not changed, it is changed after server accepts the changes.
When
new row is added, the last attribute value is generated to ensure the id to be unique.
<Cfg> bool
AppendId
[0]
When a user changes some editable cell as source id part and the id becomes
not unique:
if set to
0, the last attribute in
IdNames is automatically re-generated.
if set to
1, the generated id is appended to the existing value in the last attribute in
IdNames.
When new row is added, the cells get default values and if the row id becomes
not unique:
if set to
0, the last attribute in
IdNames is set to new generated id.
if set to
1, the generated id is appended to the default value in the last attribute in
IdNames.
renamed 6.0 <Cfg> bool
CaseSensitiveId
[1]
How to compare ids if they are unique.
If used case insensitive ids, all the ids are always lower case.
new 9.3 <I> bool
IgnoreIdNames
[0]
If set to 1, this row does not set its id by IdNames. Use for auto generated rows like group rows with auto set ids.
<Cfg> bool
FullId
[0]
If set to 1, to row
id there are added all its parent ids as id prefix, separated by '$'.
It means that the row primary key must be unique only within its parent.
If row is moved, the
id attribute is
not changed immediately, it is updated after server accept the changes.
upd 9.1 <I> string
NewId
New row id returned from server.
To change row id attribute from server you cannot set it directly, because the row will not be found, you need to set it to
NewId.
(Since 9.1) It is set also in uploaded data if the row id will be changed due IdNames or FullId settings. Only when set
Upload_Flags='NewId'
API for row ids
API event string
OnSetRowId
(TGrid grid, TRow row, string newid)
Called when new
id attribute is generated for the row. Returns new id. The row has still old id.
The
newid and returned id is value for row
id attribute. It is full id, includes all parts and optionally parent id.
It is called when new row is added or row is copied or server returns NewId for the row or the id is changed by accepting changes.
API event void
OnChangeId
(TGrid grid, TRow row, string col, type oldvalue)
Called when the id column (the last column in
IdNames) value has been automatically changed to be the id unique.
Called after a user changed some cell from
IdNames and row id became non unique and has been automatically corrected.
Called also after row move when set
FullId and the id became non unique due the move to another parent.
It is called after the change, the row contains new value in the column, the
oldvalue is original value.
API event string
OnGenerateId
(TGrid grid, TRow row, string newid)
Called when new unique part of id is generated or updated for the row. Returns new id value.
The
newid and returned id is the generated part of id, this is the value for the last attribute from
IdNames list.
API method string
GenerateId
(TRow row)
Generates new row's id and saves it to
LastId. Returns it. The id is only the last part for multi ids.
It does
not change the row id.
new 6.0 API variable TRow[ ]
Rows
read only JavaScript named array of row objects by their id
All rows in grid by their
id. Including fixed and Space rows.
If the row has set its id neither in XML nor by IdNames, the id is automatically generated as "AR"+number from 1.
upd 7.0 API method TRow
GetRowById
(string id, string attr, bool nofixed)
Searches for the row by its id.
If the row exists in
Rows, it returns the row from
Rows, otherwise it iterates all rows in grid to find the row.
The advantage to
Rows is that it can be used also before the Rows array is filled during grid creating.
The disadvantage is that it will be slow when the
Rows does
not contain given
id.
(Since 7.0) If set
attr, it searches the row according to this attribute value instead of id, in this case it always iterates all the rows.
(Since 7.0) If set
nofixed, it does
not search in fixed and space rows