Nested object data

Nested object data

tranhuuhien1990tranhuuhien1990 Posts: 9Questions: 1Answers: 0

Hi, I ref link https://datatables.net/examples/ajax/deep.html, so I have a question.
Example:
"columns": [
{ "data": "name" },
{ "data": "hr.position" },
{ "data": "contact.0" },
{ "data": "contact.1" },
{ "data": "hr.start_date" },
{ "data": "hr.salary" }
]
But when I want to add class 'text-center' for 'name' column. I must use:
'columnDefs' : [
{
'targets' : 0,
'className': 'text-center'
},
]
I want to use something as:
'targets' : 'name',

Can it?

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @tranhuuhien1990 ,

    No, columnDefs.targets doesn't support named fields, see what it can on that linked page.

    But, you can just specify the class in the columns, it doesn't need to be separate:

    "columns": [
      { "data": "name", 'className': 'text-center' },
      { "data": "hr.position" },
      { "data": "contact.0" },
      { "data": "contact.1" },
      { "data": "hr.start_date" },
      { "data": "hr.salary" }
    ]
    

    Cheers,

    Colin

  • tranhuuhien1990tranhuuhien1990 Posts: 9Questions: 1Answers: 0

    Thank you for rely me!

This discussion has been closed.