Custom property in columns.data

Custom property in columns.data

kirwlzkirwlz Posts: 3Questions: 1Answers: 0

Hello,

I would like to send an extra parameter to the server, the comparison operator which is used on the server side to search a column.
It would be fine to get it through columns[0][data][comparison].

This code seems to work well :

columns: [
    {
        data: {
            _: "firstName",
            comparison: "eq"
        }
     }
]

On the server-side, these variables are sent:

columns[0][data][_]: firstName
columns[0][data][comparison]: eq

Even if it works, I am annoyed because my data object does not respect the structure described in the documentation (_, filter, display, type or sort).
Is there a documented way to achieve what I want ?

Thanks for your answer !

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    You can send extra parameters with ajax.data.

    Colin

  • kirwlzkirwlz Posts: 3Questions: 1Answers: 0

    Hello Colin,

    Thanks for your answer !

    This option is very interesting and I managed to use it successfully with the code below :

    ajax: {
        method: 'get',
        url: myUrl,
        data: function ( data ) {
            data.columns[0].search.comparison = "eq";
            return data;
        }
    }
    

    However, I find annoying to rely on a column index (0 in this case) to add the extra parameter.
    It can make maintenance tedious.

    Is there a way to make it work without specifying the column's index ?
    To me, the optimal solution would be to add the extra parameter in the column definition.

    In this 2015's discussion, @allan says :

    I think the DataTables API is going to need to add a method to get custom properties from the column configuration to make this more straight forward.

    Did you know if it has been implemented ?

  • allanallan Posts: 63,208Questions: 1Answers: 10,415 Site admin
    Answer ✓

    No it never did I'm afraid. Currently the only way would be to do as you did (or create your own abstraction / mapping for it).

    Allan

  • kirwlzkirwlz Posts: 3Questions: 1Answers: 0

    Hello @allan,

    Thanks for your answer.

    I will try to make my own plug-in to reuse it through my projects.
    Is there an official documentation which explains how to do it ?

This discussion has been closed.