Complex styling with columnDefs

Complex styling with columnDefs

mikeosoftmikeosoft Posts: 40Questions: 14Answers: 2

Hi,
I need a way to style different columns using columnDefs.
Some columns need right alignment, and some others need a custom rendering.

Below is what I tried, but unfortunately the right alignment is not working.
Can I add multiple columnDefs like this?

            "columnDefs": [{ 
                className: "dt-right", 
                "targets": [ 4,5,6,7,8,9 ] 
            }],
            "columnDefs": [{
                "targets": [7,8,9,10,11,12,13],
                "render": function ( data, type, row, meta ) {
                    return type === 'display'?
                        '<input type="checkbox" name="group' + meta.row + '" /> ' + data:data;
                }
            }]

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    No, the second will overwrite the first when initializing. Combine them into one columnDefs option.

    Kevin

  • mikeosoftmikeosoft Posts: 40Questions: 14Answers: 2

    Using bootstrap classes did the trick for the alignment.
    Also figured out that the proper code is :

                    "columnDefs": [
                    { 
                        "targets": [ 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ],
                        "className": "text-right"                   
                    },
                    {
                        "targets": [1,2,3,4,5,6,7,8,9,10,11,12],
                        "render": function ( data, type, row, meta ) {
                            return type === 'display'?
                                '<input type="checkbox" name="group' + meta.row + '" /> ' + data:data;
                        }
                    }
                    ]  
    
  • iceman66iceman66 Posts: 3Questions: 0Answers: 0
    edited June 2018

    Help me please with a chekbox show into the table

  • iceman66iceman66 Posts: 3Questions: 0Answers: 0

    I want show a checkbox in my table, from a database field of type TINY. please help me!!!

This discussion has been closed.