Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to customize datatable ajax callback #6383

Closed
trgiangvp3 opened this issue Nov 29, 2020 · 5 comments · Fixed by #6482
Closed

How to customize datatable ajax callback #6383

trgiangvp3 opened this issue Nov 29, 2020 · 5 comments · Fixed by #6482
Assignees
Milestone

Comments

@trgiangvp3
Copy link

trgiangvp3 commented Nov 29, 2020

I saw the code in this file datatable-extension.js
At the end of datatables.createAjax function, from Line 360 to Line 368 is where the ajax request is sent.

if (callback) {
  serverMethod(input).then(function (result) {
    callback({
      recordsTotal: result.totalCount,
      recordsFiltered: result.totalCount,
      data: result.items
      });
    });
}

I have 2 questions as below

  1. If I want to customize the callback function which is called at Line 362, what should I do?
  2. How can I pass the whole result from the response to the callback function at Line 362

I could write my own code to achieve above but I wonder if there is any configuration related (if there is then what I have to do will much more simple)

ABP Framework version

3.3.1 (Stable)

User Interface:

MVC

@maliming
Copy link
Member

The callback function is belongs datatables.

https://datatables.net/reference/option/ajax

@trgiangvp3
Copy link
Author

The callback function is belongs datatables.

https://datatables.net/reference/option/ajax

It would be nice if ABP could provide a customizable calback like below

    createAjax: function (serverMethod, inputAction, responseCallback) {
      return function (requestData, callback, settings) {

        // same old code

        if (callback) {
          serverMethod(input).then(result => {
            callback({
              recordsTotal: result.totalCount,
              recordsFiltered: result.totalCount,
              data: result.items
            });
            if (responseCallback)
              responseCallback(result);
          });
        }
      };

@maliming maliming self-assigned this Dec 4, 2020
@maliming maliming added this to the 4.1-preview milestone Dec 4, 2020
@maliming
Copy link
Member

maliming commented Dec 4, 2020

ok, I will give it a try.

@maliming
Copy link
Member

maliming commented Dec 4, 2020

See https://github.com/abpframework/abp/pull/6482/files

@trgiangvp3
Copy link
Author

See https://github.com/abpframework/abp/pull/6482/files

Thank you. That's exactly what I want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants