[Help] alignment TD in DataTables

[Help] alignment TD in DataTables

shihyishihyi Posts: 3Questions: 0Answers: 0
edited July 2011 in General
Dear All,

I am a beginner of DataTables.
I try to dynamic create table use fnAddData.
The code of jQuery as following.
[code]
$('#demo2').click(function() {
$('#example').dataTable().fnAddData(
[
'1',
'2'
]
);
});
[/code]

And HTML as following.
[code]
Run



Head_1
Head_2





[/code]

I want Head_1 alignment to center and Head_2 to right.
How can I do that?


Best Regards,
Shihyi Chiu

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    Shihyi,

    This is primarily a CSS issue. You can add CSS classes with DataTables using sClass (http://www.datatables.net/usage/columns#sClass) and then style them accordingly. Decide what your "default" column will use for alignment, and then in your CSS file, add:

    td, th { text-align: center }

    (for centering). And then whichever class you add with sClass, style that one separately:

    td.right, th.right { text-align: right }

    Greg
  • shihyishihyi Posts: 3Questions: 0Answers: 0
    Dear Greg,

    Thanks for your reply.
    The problem is solved after I add some CSS and use sClass.
    Thanks again for your help.


    Best Regards,
    Shihyi Chiu
This discussion has been closed.