Adding custom parameters to columns (ajax sent request)

Adding custom parameters to columns (ajax sent request)

ibgdibgd Posts: 4Questions: 2Answers: 0

Hello,

I'm aware of ajax.data (https://datatables.net/reference/option/ajax.data), however I would like to add custom parameters to each column. It looks like even if I add new parameter to the column object, they don't make it to the ajax sent request data (only pre-defined parameters show on the request, such as data, name, title and so on...). So on the server side, I don't have those custom parameters to work with. Is is possible to do that?

What i'm trying to achieve:

columns: [
{
data: 'mycol',
name: 'My Col',
myCustomParameter: 'My Custom Value'
...
}
]

but the ajax request sent only has:

columns: [
{
data: 'mycol',
name: 'My Col',
...
}
]

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited August 2018

    How are you getting the column settings to send via ajax.data?

    Are you setting the columns configuration directly in Datatables or via a variable that you assign to columns?

    Without seeing what you are doing my recommendation would be to build a columns object variable that include your additional parameters before initializing Datatables. Then use this variable to send using ajax.data. I suspect that any Datatables initialization parameters that are invalid are discarded during initialization ss they aren't used.

    Kevin

  • ibgdibgd Posts: 4Questions: 2Answers: 0

    "build a columns object variable with your additional parameters"

    That's a good idea, which I didn't think about. I'm already passing other data using ajax.data, it's more work to create another object and have to match them later, but I think this would work.

    Thanks.

This discussion has been closed.