RTL in DataTable PDF export

Viewed 44

The below is fine but with the column containing long text in Arabic the first line became the second line and the second line become the first line:

$('#table').dataTable({
    buttons: [
        {
            extend: 'pdfHtml5',
            text: 'PDF',
            exportOptions: {
                columns: ':visible',
                modifier: {order: 'index'},
                format: {
                    body: function (data, row, column, node) {
                        const arabic = /[\u0600-\u06FF]/;

                        if (arabic.test(data)) {
                            return data.split(' ').reverse().join(' ');
                        }
                        return data;
                    },
                    header: function (data, row, column, node) {
                        const arabic = /[\u0600-\u06FF]/;

                        if (arabic.test(data)) {
                            return data.split(' ').reverse().join(' ');
                        }
                        return data;
                    }
                }
            }
        }
    ],
})

Here is an image of the text:

enter image description here

0 Answers
Related