how to reverse excel/pdf columns order to rtl?

how to reverse excel/pdf columns order to rtl?

mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

i'm trying to export data in excel or pdf , it's already rtl on the page but when i export it ,columns reverse order to ltr.
i tried to use this option in the button object but didn't work:
exportOptions: { columns: ':not(.select-checkbox)', modifier: { order: 'current' }, order: 'asc', }
exportOptions: { columns: ':not(.select-checkbox)', modifier: { order: 'index' }, order: 'desc', }

This question has an accepted answers - jump to answer

Answers

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

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    thanks for the answer, i already have arabic font, but the words are reversed.
    by taking a look i found that pdfmake doesn't support rtl, and i didn't get the idea of convert checkbox example.
    so any other recommendation?

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

    Did you read that thread? There's a recommendation in my last comment.

    Colin

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    yes, i read it but i didn't get where to put the reverse function in my code, only i can put orthogonal: "myExport" to exportOptions .
    here is the pdf button code

    { extend: 'pdfHtml5', text: 'PDF', customize: function (doc) { doc.defaultStyle = { font: 'Cairo' }; }, titleAttr: 'Generate PDF', className: 'btn-outline-danger btn-sm ', exportOptions: { columns: ':not(.select-checkbox)', modifier: { order: 'index' } }, }

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0
    edited May 2020

    my table dir="rtl", but pdf doesn't read this, is there any property to change columns order?

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

    This here is an implementation of my last comment in that thread - it's flipping the strings. You'll need to do something like that.

    Colin

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    it's working B) , thank you so much you are a great person o:) thanks for your patient.
    just on more thing i want to do, i want to reverse all table's columns order in the pdf .. is that possible in the same way?

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

    Yep, change columnDefs.targets to be _all,

    Colin

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    sorry, maybe i couldn't explain the problem well, what i want is reverse columns sorting, so if i have name / age / office, i want it to be office / age / name..

    also in the implementation above the function doesn't effects the table head cells.

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    also changing columnDefs.targets to be _all , gives unexpected output , it reverse html elements also

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0

    live.datatables.net/himufifu/1/edit

    here i give body element dir="rtl" , but when i export it to pdf table columns reverse back to ltr

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Unfortunately the pdf export does not currently consider rtl text. I'm not even sure if pdfmake supports rtf - I'm not seeing it in their documentation. It would need to be added in that library before we can offer any support for it I'm afraid.

    Allan

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0
    edited May 2020
    extend: 'pdf',
                    text: 'PDF',
                    customize: function (doc) {
                      doc.defaultStyle =
                      {
                        font: 'Cairo',
                      };
                    }
    

    in defaultStyle object is there direction property to set it rtl

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Can you give me the link to that in the pdfmake docs please?

    Allan

  • mostafashabanmostafashaban Posts: 11Questions: 2Answers: 0
    edited May 2020

    thanks @allan for respond , this part of my code to export arabic font in pdf, maybe it will help someone else:


    var DT1 = $('#dt-basic-example').DataTable({ columnDefs: [ //revese arabic words for pdf exporting { // target columns to reverse words targets: [2,3,4,5], render: function (data, type, row) { if (type === 'myExport') { return data.split(' ').reverse().join(' '); } return data; } }] //PDF { extend: 'pdf', text: 'PDF', customize: function (doc) { doc.defaultStyle = { font: 'Cairo', }; }, titleAttr: 'Generate PDF', className: 'btn-outline-danger btn-sm ', exportOptions: { columns: ':not(.select-checkbox)', orthogonal: "myExport", modifier: { order: 'index', page: 'current' } }, }, //...... });
  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    this worked for me, but the header of table words not reversed

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    also is there a way to reverse the columns mean that last column in table rendered in first an so on, those together reversing in doc content and table columns will solve RTL problem and finally reverse in doc title

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

    columns: [ "the index of the column that you want to export in reverse" ]

    columns: [0,1,2,3 ]
    put them like this
    columns: [3,2,1,0 ]

This discussion has been closed.