Browse Source

Merge pull request #6482 from abpframework/maliming/responseCallback

Add responseCallback to datatables.createAjax function.
pull/6532/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
04650736f3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      docs/en/UI/AspNetCore/Data-Tables.md
  2. 15
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js

28
docs/en/UI/AspNetCore/Data-Tables.md

@ -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. 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 ### 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. `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.
@ -260,4 +286,4 @@ Assuming that the possible values for a column data is `f` and `m`, the `gender`
## Other Data Grids ## Other Data Grids
You can use any library you like. For example, [see this article](https://community.abp.io/articles/using-devextreme-components-with-the-abp-framework-zb8z7yqv) to learn how to use DevExtreme Data Grid in your applications. You can use any library you like. For example, [see this article](https://community.abp.io/articles/using-devextreme-components-with-the-abp-framework-zb8z7yqv) to learn how to use DevExtreme Data Grid in your applications.

15
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js

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

Loading…
Cancel
Save