Merge pull request #6482 from abpframework/maliming/responseCallback

Add responseCallback to datatables.createAjax function.
pull/6532/head
Halil İbrahim Kalkan 4 years ago committed by GitHub
commit 04650736f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -105,6 +105,32 @@ The `abp.libs.datatables.createAjax` method (used in the example above) adapts r
This works automatically, so most of the times you don't need to know how it works. See the [DTO document](../../Data-Transfer-Objects.md) if you want to learn more about `IPagedAndSortedResultRequest`, `IPagedResult` and other standard interfaces and base DTO classes those are used in client to server communication.
The `createAjax` also supports you to customize request parameters and handle the responses.
**Example:**
````csharp
var inputAction = function () {
return {
id: $('#Id').val(),
name: $('#Name').val(),
};
};
var responseCallback = function(result) {
// your custom code.
return {
recordsTotal: result.totalCount,
recordsFiltered: result.totalCount,
data: result.items
};
};
ajax: abp.libs.datatables.createAjax(acme.bookStore.books.book.getList, inputAction, responseCallback)
````
### Row Actions
`rowAction` is an option defined by the ABP Framework to the column definitions to show a drop down button to take actions for a row in the table.

@ -325,7 +325,14 @@
* AJAX extension for datatables *
*************************************************************************/
(function () {
datatables.createAjax = function (serverMethod, inputAction) {
datatables.createAjax = function (serverMethod, inputAction, responseCallback) {
responseCallback = responseCallback || function(result) {
return {
recordsTotal: result.totalCount,
recordsFiltered: result.totalCount,
data: result.items
};
}
return function (requestData, callback, settings) {
var input = inputAction ? inputAction(requestData, settings) : {};
@ -359,11 +366,7 @@
if (callback) {
serverMethod(input).then(function (result) {
callback({
recordsTotal: result.totalCount,
recordsFiltered: result.totalCount,
data: result.items
});
callback(responseCallback(result));
});
}
};

Loading…
Cancel
Save