-
Notifications
You must be signed in to change notification settings - Fork 0
api_actions
An action defines how to communicate from the client to the server. There are four types of actions:
- listAction: Defines how to get the list of records.
- createAction: Defines how to submit a "create new record" form.
- updateAction: Defines how to submit an "edit record" form.
- cloneAction: Defines how to submit a "clone record" form.
- deleteAction: Defines how to delete a record.
Actions must be defined in the actions list of FTable options:
actions: {
// Action definitions go here
}An action value can be a URL string or a function. See each action for details.
- Type: URL string or function
- Default: None
If listAction is defined as a URL string, FTable makes an AJAX POST request to this URL to fetch the list of records. The URL must return a JSON object:
{
"Result": "OK",
"Records": [
{ "PersonId": 1, "Name": "Benjamin Button", "Age": 17, "RecordDate": "/Date(1320259705710)/" },
{ "PersonId": 2, "Name": "Douglas Adams", "Age": 42, "RecordDate": "/Date(1320259705710)/" }
]
}-
Result: Can be
"OK"or"ERROR". If"OK", theRecordsproperty must contain an array of records. - Records: An array of records to display in the table.
-
Message: If
Resultis"ERROR", this property explains the error.
-
/Date(milliseconds)/: Example:/Date(1320259705710)/. -
YYYY-MM-DD HH:MM:SS: Example:2012-01-03 21:40:42. -
YYYY-MM-DD: Example:2012-01-03.
If paging is enabled, FTable sends the following query string parameters:
-
jtStartIndex: Start index of records for the current page. -
jtPageSize: Maximum number of records to fetch.
The server must return:
-
TotalRecordCount: Total number of records (not just the current page).
If sorting is enabled, FTable sends:
-
jtSorting: A string representing the sorting request (e.g.,Name ASC,BirthDate DESC).
You can define listAction as a function. The function can return:
- The data itself.
- A promise to return the data.
Example using modern fetch API:
listAction: function (postData, jtParams) {
return fetch('/Demo/StudentList', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
throw error;
});
}Example using async/await:
listAction: async function (postData, jtParams) {
try {
const response = await fetch('/Demo/StudentList', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
});
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}-
postData: Data provided when calling the
loadmethod. -
jtParams: Contains
jtStartIndex,jtPageSize, andjtSortingif paging or sorting is enabled.
- Type: URL string or function
- Default: None
If createAction is defined as a URL, FTable makes an AJAX POST request to this URL to save a new record. The URL must return a JSON object:
{
"Result": "OK",
"Record": { "PersonId": 5, "Name": "Dan Brown", "Age": 55, "RecordDate": "/Date(1320262185197)/" }
}-
Result: Can be
"OK"or"ERROR". -
Record: The newly created record (required if
Resultis"OK"). -
Message: Error message if
Resultis"ERROR"(required in the ERROR case, otherwise a "communication error" will be shown). If this property is present whenResultis"OK", then an info-dialog will show with this message after the record has been inserted (only if the insert is done via the add-record button in the toolbar).
You can define createAction as a function. The function can return:
- The data itself.
- A promise to return the data.
Example using modern fetch API:
createAction: function (postData) {
return fetch('/Demo/CreatePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
throw error;
});
}Example using async/await:
createAction: async function (postData) {
try {
const response = await fetch('/Demo/CreatePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
});
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}- Type: URL string or function
- Default: None
If updateAction is defined as a URL, FTable makes an AJAX POST request to this URL to update a record. The URL must return a JSON object:
{
"Result": "OK",
"Record": { "Name": "Dan Brown", "Age": 55, "LastUpdateDate": "/Date(1320262185197)/" }
}-
Result: Can be
"OK"or"ERROR". - Record: Optional. Overwrites fields in the updated record.
-
Message: Error message if
Resultis"ERROR"(required in the ERROR case, otherwise a "communication error" will be shown). If this property is present whenResultis"OK", then an info-dialog will show with this message after the record has been updated (only if the update is done via the update-button in the table).
You can define updateAction as a function. The function can return:
- The data itself.
- A promise to return the data.
Example using modern fetch API:
updateAction: function (postData) {
return fetch('/Demo/UpdatePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
throw error;
});
}Example using async/await:
updateAction: async function (postData) {
try {
const response = await fetch('/Demo/UpdatePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
});
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}- Type: URL string or function
- Default: None
If cloneAction is defined as a URL, FTable makes an AJAX POST request to this URL to clone a record. The URL must return a JSON object:
{
"Result": "OK",
"Record": { "Name": "Dan Brown", "Age": 55, "RecordDate": "/Date(1320262185197)/" }
}-
Result: Can be
"OK"or"ERROR". - Record: Optional. Overwrites fields in the cloned record.
-
Message: Error message if
Resultis"ERROR"(required in the ERROR case, otherwise a "communication error" will be shown). If this property is present whenResultis"OK", then an info-dialog will show with this message after the record has been cloned (only if the clone is done via the clone-button in the table).
You can define cloneAction as a function. The function can return:
- The data itself.
- A promise to return the data.
Example using modern fetch API:
cloneAction: function (postData) {
return fetch('/Demo/ClonePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
throw error;
});
}Example using async/await:
cloneAction: async function (postData) {
try {
const response = await fetch('/Demo/ClonePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
});
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}- Type: URL string or function
- Default: None
If deleteAction is defined as a URL, FTable makes an AJAX POST request to this URL to delete a record. The URL must return a JSON object:
{
"Result": "OK"
}-
Result: Can be
"OK"or"ERROR". -
Message: Error message if
Resultis"ERROR"(required in the ERROR case, otherwise a "communication error" will be shown). If this property is present whenResultis"OK", then an info-dialog will show with this message after the record has been deleted (only if the delete is done via the delete-button in the table).
You can define deleteAction as a function. The function can return:
- The data itself.
- A promise to return the data.
Example using modern fetch API:
deleteAction: function (postData) {
return fetch('/Demo/DeletePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
throw error;
});
}Example using async/await:
deleteAction: async function (postData) {
try {
const response = await fetch('/Demo/DeletePerson', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(postData)
});
return await response.json();
} catch (error) {
console.error('Error:', error);
throw error;
}
}