1

I am using jQuery data tables and fill the data via ajax as json: https://datatables.net/examples/ajax/simple.html

var tbl = $('.mytbl').DataTable({
   "ajax": {
      url: "ajax/getData.php",
      type: "POST"
   }
});

The response of getData.php will be like this:

$myArray['data'][] = array(
   "Value 1",
   "Value 2",
   "Value 3"
} 
echo json_encode($myArray);

This works fine: But how can I define that - for example - value 2 should be text-align right in my table?

1
  • can you share your html codes ? Commented Aug 13, 2021 at 6:38

2 Answers 2

2

Try this

   var tbl = $('.mytbl').DataTable({
       "ajax": {
          url: "ajax/getData.php",
          type: "POST"
       },
       'columnDefs': [{
            "targets": 1,
            "className": "text-right",
       }]
    });
Sign up to request clarification or add additional context in comments.

Comments

0

You can use render method available in Datatables.

{
    data: 'value 2 column',
    render: function ( data, type, row ) {
        return `<span style="text-align:right">${data}</span>`;
    }
}

You can also use css if all column values are right aligned.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.