From 9217fcf1cafb3e342b509ec69acc28db2c3253bd Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Wed, 3 Feb 2021 15:59:15 +0000 Subject: [PATCH] Improve DataTable.Net AJAX Adapter (abp.libs.datatables.createAjax) function --- docs/en/UI/AspNetCore/Data-Tables.md | 10 +++++++++- .../datatables/datatables-extensions.js | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/en/UI/AspNetCore/Data-Tables.md b/docs/en/UI/AspNetCore/Data-Tables.md index b97d49d562..3dea38d179 100644 --- a/docs/en/UI/AspNetCore/Data-Tables.md +++ b/docs/en/UI/AspNetCore/Data-Tables.md @@ -110,7 +110,7 @@ The `createAjax` also supports you to customize request parameters and handle th **Example:** ````csharp -var inputAction = function () { +var inputAction = function (requestData, dataTableSettings) { return { id: $('#Id').val(), name: $('#Name').val(), @@ -131,6 +131,14 @@ var responseCallback = function(result) { ajax: abp.libs.datatables.createAjax(acme.bookStore.books.book.getList, inputAction, responseCallback) ```` +If you don't need access or modify the `requestData` or the `dataTableSettings`, you can specify a **simple object** as the second parameter. + +**Note:** This option should not be used if you need to customise any of the following options: `maxResultCount`, `skipCount`, `sorting`, `filter` - these options will be overwritten by the `createAjax` function so you should specify an `inputAction` **function** instead. + +````javascript +ajax: abp.libs.datatables.createAjax(acme.bookStore.books.book.getList, { id: $('#Id').val(), name: $('#Name').val() }) +```` + ### 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. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js index 1808f267eb..9895097d99 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/wwwroot/libs/abp/aspnetcore-mvc-ui-theme-shared/datatables/datatables-extensions.js @@ -334,7 +334,10 @@ }; } return function (requestData, callback, settings) { - var input = inputAction ? inputAction(requestData, settings) : {}; + var input = typeof inputAction === 'function' + ? inputAction(requestData, settings) + : typeof inputAction === 'object' + ? inputAction : {}; //Paging if (settings.oInit.paging) {