What's the right way to map response values to DT?

What's the right way to map response values to DT?

EndUserEndUser Posts: 5Questions: 2Answers: 0

According to the manual, DT expects the response to have certain values. However, if the server can't be made to change those parameters but does contain the information, how can I map the response to fields that DT is expecting? For example, DT expect to see {recordsTotal: 14} in the response, but my server wants to send {totalElements:14}. Is there an way to map that value to the expected parameter?

Answers

  • EndUserEndUser Posts: 5Questions: 2Answers: 0

    Ok, so it says I can use the dataSrc property for a transformation function. Here's an example of what I've tried:

    ajax: {
        url: '/position/19',
        dataSrc(json){
            json.recordsTotal=json.totalElements
            console.log('ajax called', json)
            return json.content;
        }
    },
    

    (my data containing object is called 'content')

    This sets recordsTotal correctly. Now, I need to figure out if I can do the same with the current page and total pages.

This discussion has been closed.