How can I set alignment of columns to right ?

How can I set alignment of columns to right ?

gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0
edited February 2022 in DataTables

I want to align the column to right for numbers How can I do it ? I seen this link from here but its not working for me.

https://datatables.net/forums/discussion/comment/139922/#Comment_139922

Is there any other way.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This example is from that thread, and it appears to be working as expected. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0

    Thank you for the response, Yes I will check this and revert back asap.

  • gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0

    This will work only on screen .. I am extending a button to export data as JSOn and send to a notepad for text printing

    {
    extend: 'copy',
    text: 'Print',
    action: function ( e, dt, button, config ) {
    var data = dt.buttons.exportData(
    {
    columnDefs: {targets: [3,4], className: 'numberColumn'}
    }
    );
    var jsonData = JSON.stringify( data ) ;
    doPrint(data);
    }
    }

    in my notepad it always come without any text-align ?!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    The alignment is done on the table with classes - you're just exporting the data which doesn't have an alignment, it's just a number.

    Colin

  • gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0

    is it possible to export data with alignment ? if possible how can I do it ? thank you for the help.

  • gopi.jtech@gmail.comgopi.jtech@gmail.com Posts: 9Questions: 3Answers: 0
    edited February 2022
    $('#myTable').DataTable({
                columnDefs: [{
          targets: [3], className: 'numberColumn'
        }],
                "ordering": false,
                "paging": false,
                dom: 'Blfrtip',
                buttons: [
                    'copy', 'csv', 'excel', 'pdf', //extended  for dotmatrix printing
                    {
                    extend: 'copy',
                    text: 'Print',
                    action: function ( e, dt, button, config ) {
                        var data = dt.buttons.exportData(
                            {
                                 columnDefs: {targets: [3], className: 'numberColumn'}
                            }
                        );
    
                           var jsonData =    JSON.stringify( data )  ;                      
    
                           doPrint(data);
    
                    }
    
                }
                ]
            });
    

    The above code works perfect with alignment for csv,excel, pdf but not for the extended button. Is it possible to do that. Please help me, thanks in advance.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Please see my last message, the same applies. It's just a string, without indentation. You could pad it with spaces, but that's the best you'll get.

    Colin

Sign In or Register to comment.