This topic contains 3 replies, has 2 voices, and was last updated by Sean Sean 1 year, 10 months ago.

Datatables change column text data to right aligned


  • woonipad
    Participant

    Posts: 3
    Member Reply #5935

    Hello,
    I want to change text in some of my data in column of datatable to right aligned. I am using this code:

    columnDefs: [
    {"className": "dt-right", "targets": "0"}
    ]

    However, the column does not change to right aligned. Please tell me how to change the column text from some of my column. Thanks in advance.

    Sean
    Sean
    Keymaster

    Posts: 4226
    Support Staff Reply #5951

    Hi,

    Please double check your datatable initialization code and make sure “columnDefs” parameter is defined once and holding all column default parameters within the same array. I suspect you have 2 columnDefs parameter in the initialization code where the second one is overrides the first once. The below code was tested and worked fine:

    “columnDefs”: [

    {  // set default column settings

    ‘orderable’: false,

    ‘targets’: [0]

    },

    {

    “searchable”: false,

    “targets”: [0]

    },

    {

    “className”: “dt-right”,

    “targets”: [2]

    }

    ],


    woonipad
    Participant

    Posts: 3
    Member Reply #5997

    I have include all 3 scripts which are:

    <script src="/IsisWMS-War/assets/global/scripts/datatable.js" type="text/javascript"></script>
    <script src="/IsisWMS-War/assets/global/plugins/datatables/datatables.min.js" type="text/javascript"></script>
    <script src="/IsisWMS-War/assets/global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.js" type="text/javascript"></script>

    And I also use <script src=”../assets/pages/scripts/table-datatables-ajax.min.js” type=”text/javascript”></script> where I edit this js and change columnDefs, but nothing changed.

    columnDefs: [
    { // set default column settings
    orderable: false,
    targets: [0]
    },
    {
    searchable: false,
    targets: [0]
    },
    {
    className: 'dt-right',
    targets: '_all'
    }
    ],

    Hope to get this issue solved. Thanks

    Sean
    Sean
    Keymaster

    Posts: 4226
    Support Staff Reply #6013

    Hi,

    Can you please provide us a test link to your site in a private reply ? We will need to check your code online in order to investigate it further.

    Thanks.

Tagged: 

You must be logged in to reply to this topic.