Does anyone know how to right align columns with numeric value with infyom laravel-generator yajra datatable.
From this Doc you have add the render parameter, but I did not find a solution to add it with Infyom.
Thank in advance.
My Answer:
To right align numeric values in Yajra DataTable generated by Infyom Laravel Generator, you can use the `columnDefs` option in the DataTable initialization. Here's how you can do it:
1. In your controller where you are generating the DataTable, you can add the `columnDefs` option to the DataTable initialization like this:
javascript
$('#dataTable').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('your.route.name') }}",
columns: [
{ data: 'id', name: 'id' },
{ data: 'name', name: 'name' },
{ data: 'amount', name: 'amount' },
// Add more columns as needed
],
columnDefs: [
{ className: "text-right", targets: [2] } // Right align the third column (index 2)
]
});
2. In your blade view file where you are displaying the DataTable, make sure to include the DataTable initialization script:
html
ID
Name
Amount
By adding the `columnDefs` option with the `className: "text-right"` property, you can right align the numeric values in the specified column. Just make sure to adjust the `targets` index to match the correct column index in your DataTable.
Rate this post
5 of 5 based on 5019 votesComments