Add property to DataTables,

Add property to DataTables,

ciroracirora Posts: 29Questions: 2Answers: 1
edited August 2014 in Free community support

Hi,
I want to init columns outside $().DataTable. How can I do it?
My code:

COLONNE='{data:"first_name"},{data:"last_name"}'
var  TABELLA = $('#example').DataTable( {

        dom: 'C<"clear">Tlfrtip',
        "columns":COLONNE
});

but it doesn't work.
I tried eval(COLONNE) and window[COLONNE] but nothing.
Help please

Replies

  • ciroracirora Posts: 29Questions: 2Answers: 1

    Hi,
    maybe this way isn't right one.
    Is it possible to retrieve
    columns:[{data:values_1},{data:values_2}]
    from the thead of the table???

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin

    The COLONNE variable is a string above, not a Javascript object. Remove quotes and it should work.

    Allan

  • ciroracirora Posts: 29Questions: 2Answers: 1
    edited August 2014

    Thanks for the answer,
    I have this Error:
    Errore: TypeError: aoColumns[srcCol] is undefined
    Path: /media/js/jquery.dataTables.js

    I tried

    COLONNE={"data":"first_name"},{"data":"last_name"};
    COLONNE={"data":"first_name","data":"last_name"}
    COLONNE={data:"first_name",data:"last_name"}
    

    No one works. Other solutions?

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    COLONNE=[ {"data":"first_name"},{"data":"last_name"} ];
    

    is what you want.

    See the columns documentation and the examples in columns.data.

    Allan

  • ciroracirora Posts: 29Questions: 2Answers: 1
    edited August 2014

    Thanks Allan,
    it works.
    Great.

This discussion has been closed.