GridView and DataList data synchronization

Grid View back-end and front-end synchronization

For a Grid View control to be able to be displayed in the front-end side of the application its content and data needs to be synchronized between the front-end and the back-end of the application. To accomplish this, there are two key components that serve as communicators between the application's server and the client's browser. Those components are the following:
  • Grid View and controls models.
  • Web API controller calls.

Grid View and controls models

The Grid View model is a data representation of the basic information that is needed to render its respective component in the front-end application, it mainly contains the visual structure of the control such as visibility, position, page size. This model also contents its events and the associated references to its controls model id.
Here we can see an example of a Grid View model:
1
{
2
"AllowPaging": true,
3
"AllowSorting": true,
4
"AutoGenerateColumns": false,
5
"AutoGenerateSelectButton": false,
6
"HeaderStyle": {
7
"HorizontalAlign": 2,
8
"CssClass": "GridHeader"
9
},
10
"PageSize": 10,
11
"SelectedIndex": -1,
12
"GridLines": 2,
13
"Attributes": {},
14
"CssClass": "Grid",
15
"AutoSize": false,
16
"Controls": {
17
"3d61bad3-ec06-4aaa-9579-e0bd2b88b89d": true,
18
"78a7057c-7164-4c5e-b4c9-50dab41db9e8": true,
19
"08ac587f-89ce-4321-be08-bb81b8bcb54c": true,
20
"c0b33875-e6f6-4973-9f69-da7cf4728df9": true,
21
},
22
"Enabled": true,
23
"EventChanges": {
24
"Sorting": true,
25
"PageIndexChanging": true
26
},
27
"Focused": false,
28
"Name": "grdDeals",
29
"Parent": "a91ed5a6-f71a-45bc-873b-192082098c64",
30
"Refresh": true,
31
"Style": {},
32
"ShowTooltip": false,
33
"TabIndex": 0,
34
"TabStop": true,
35
"Text": "",
36
"Visible": true,
37
"ZIndexRefresh": false,
38
"Id": "1571c471-dbd0-479f-aff8-1e192158bfd3",
39
"MapperId": "grdvw",
40
"References": {}
41
},
Copied!
But this is necessary to load API calls to be explained in the following section. It's important to mention if we only load the grid and its controls, we'll the rendered control should be empty as you can see here:

Web API controller calls

Once the GridView's basic properties sent via model are synchronized, the data for the Grid View is retrieved by API calls, each one with one single responsibility. The GridView model has a Refresh flag used to flag is used to notify the front-end some changes in the data set to be requested by this mechanism.

GetColumns API

This API is in charge of loading the information of column’s information in order to display them as required, it contains an array with the column’s representation including properties such as the style, the header text, sort expression, data text field, it also includes events information related events related to this column and in an object apart, we can see the caption and the name for this column, each column will be represented as we can see here:
1
"Cols": [
2
{
3
"ContainingField": {
4
"HeaderStyle": {
5
"BorderStyle": "None",
6
"HorizontalAlign": "NotSet",
7
},
8
"HeaderText": "Record No",
9
"Name": null,
10
"ItemStyle": {
11
"BorderStyle": "None",
12
"HorizontalAlign": "NotSet",
13
},
14
"SortExpression": "RecordNumber",
15
"Visible": true,
16
"Id": "3d1f0272-361f-4c8a-8382-f4df538108e4",
17
"DataNavigateUrlFields": [
18
"DealId"
19
],
20
"DataTextField": "RecordNumber",
21
"Text": null,
22
"EventChanges": {
23
"NavigateToPage": true
24
}
25
}
26
},
27
{
28
"caption": "Record No",
29
"name": "Record No"
30
},
31
]
Copied!

GetIndexPage API

This API call receives as argument the index of the page that is going to be shown and returns the representation of the rows that will be displayed in the grid. It contains the length of the rows, the styles in case there is some style for any row set and the rows array with the data based on the columns explained on GetColumns API but basically composed by the column name and the column value, also we can see the DataControlFields array inside which is the info for set the different controls that could be into the grid like HyperLinkField in case that we need to show a link in this cell.
1
{
2
"Rows": [
3
{
4
"RowId": "dfa8923b-9a2d-40a3-85c4-ed9f57ac72a3",
5
"Record No": "3054",
6
"Client Name": "clientname-test",
7
"Client Code": "12345",
8
"DataControlFields": [
9
{
10
"Text": "3054",
11
"ContainingFieldType": "HyperLinkField",
12
"Controls": {}
13
},
14
{
15
"Text": "clientname-test",
16
"ContainingFieldType": "BoundField",
17
"Controls": {}
18
},
19
{
20
"Text": "12345",
21
"ContainingFieldType": "BoundField",
22
"Controls": {}
23
}
24
]
25
}
26
],
27
"Styles": [],
28
"Length": 1
29
}
Copied!

GetRangedPage API

Finally, this API should send to front-end the information with the data of the rows that are selected to be displayed on visual representation given the arguments required. Those arguments are only skip and take. The structure is very simple and has the same representation of GetIndexPage API, as you can see is only the list of rows, the style, and the length of the rows array. Is important to mention that this API is mainly used to load the GridView data when the virtual scroll feature is turned on.
1
{
2
"Rows": [
3
{
4
"RowId": "dfa8923b-9a2d-40a3-85c4-ed9f57ac72a3",
5
"Record No": "3054",
6
"Client Name": "clientname-test",
7
"Client Code": "12345",
8
"DataControlFields": [
9
{
10
"Text": "3054",
11
"ContainingFieldType": "HyperLinkField",
12
"Controls": {}
13
},
14
{
15
"Text": "clientname-test",
16
"ContainingFieldType": "BoundField",
17
"Controls": {}
18
},
19
{
20
"Text": "12345",
21
"ContainingFieldType": "BoundField",
22
"Controls": {}
23
}
24
]
25
}
26
],
27
"Styles": [],
28
"Length": 0
29
}
Copied!
After the API calls, the grid shows the information and the row page completely full as you can see in the following image

DataList back-end and front-end synchronization

The DataList control is used to display a template data bound list, this controls can be manipulated by using templates. In a similar manner as the Grid View control reviewed before this control sends by model its principal properties, however, in this case, we only handle a single Web API controller call.

DataList model and Controls

The DataList model is a data representation of the basic information that is needed to render its respective component in the front-end application. It mainly contents the visual structure of the control like visibility, position, page size.
Here we can see an example of a Grid View model
1
{
2
"ItemStyle": {
3
"CssClass": "DataListItem"
4
},
5
"AlternatingItemStyle": {
6
"CssClass": "DataListAlternatingItem"
7
},
8
"Attributes": {},
9
"AutoSize": false,
10
"Enabled": true,
11
"EventChanges": {
12
"ItemCommand": true
13
},
14
"Focused": false,
15
"Name": "dataList",
16
"Parent": "e6d3c88c-86b4-4da4-924c-767355d46d72",
17
"Refresh": true,
18
"Style": {},
19
"ShowTooltip": false,
20
"TabIndex": 0,
21
"TabStop": true,
22
"Text": "",
23
"Visible": true,
24
"ZIndexRefresh": false,
25
"Id": "a695c8a1-d796-4b44-919a-6a3371b045ec",
26
"MapperId": "dtlst",
27
"References": {}
28
},
Copied!
Same as the GridView, just with the model is not enough to see the correct behavior of this control, we need to charge the data as we’ll in the next section, but here we can see only with the model info:

GetControlsId Web API controller call

In order to set some controls to the DataList in frontend is required to invoke this Web API call, it only contains objects composed by an array of key/value elements where the key is the control’s name and the value is the unique id or MobilizeId for this control for every row in shown, with this information front-end link this control with this DataList, as we can see here this an example for a response of this API call:
1
[
2
{
3
"hidID": "4486bd0c-cc2a-4246-bf4c-8cc9a832db06",
4
"hidIsNew": "d547d7ab-e182-4539-b1a7-a6d0d837e997",
5
"txtCounterpartyName": "ee4ea4fe-f400-407d-a88e-87123c83b5dd"
6
},
7
{
8
"hidID": "9523215c-bc8c-4533-87ea-23b43d2f2871",
9
"hidIsNew": "ec2da901-6a49-468f-a215-828fba3e85b8",
10
"txtCounterpartyName": "7b03d932-bff2-40f9-8efc-e69e478b48e7"
11
}
12
]
Copied!
Now with this information loaded we are able to see the correct presentation of the DataList as we show bellow: