Right align number and center statuses in data tables

This commit is contained in:
Hillel Coren 2016-12-25 23:43:57 +02:00
parent 7b4df952f4
commit a7858a8561
7 changed files with 50 additions and 8 deletions

View File

@ -64,4 +64,30 @@ class EntityDatatable
return $data; return $data;
} }
public function rightAlignIndices()
{
return $this->alignIndices(['amount', 'balance', 'cost']);
}
public function centerAlignIndices()
{
return $this->alignIndices(['status']);
}
public function alignIndices($fields)
{
$columns = $this->columnFields();
$indices = [];
foreach ($columns as $index => $column) {
if (in_array($column, $fields)) {
$indices[] = $index + 1;
}
}
return $indices;
}
} }

View File

@ -98,7 +98,7 @@ class PaymentDatatable extends EntityDatatable
} }
], ],
[ [
'payment_status_name', 'status',
function ($model) { function ($model) {
return self::getStatusLabel($model); return self::getStatusLabel($model);
} }
@ -140,7 +140,7 @@ class PaymentDatatable extends EntityDatatable
private function getStatusLabel($model) private function getStatusLabel($model)
{ {
$label = trans('texts.status_' . strtolower($model->payment_status_name)); $label = trans('texts.status_' . strtolower($model->status));
$class = 'default'; $class = 'default';
switch ($model->payment_status_id) { switch ($model->payment_status_id) {
case PAYMENT_STATUS_PENDING: case PAYMENT_STATUS_PENDING:

View File

@ -62,7 +62,7 @@ class PaymentRepository extends BaseRepository
'invoices.is_deleted as invoice_is_deleted', 'invoices.is_deleted as invoice_is_deleted',
'gateways.name as gateway_name', 'gateways.name as gateway_name',
'gateways.id as gateway_id', 'gateways.id as gateway_id',
'payment_statuses.name as payment_status_name' 'payment_statuses.name as status'
); );
$this->applyFilters($query, ENTITY_PAYMENT); $this->applyFilters($query, ENTITY_PAYMENT);

View File

@ -2225,7 +2225,6 @@ $LANG = array(
'vendor_name' => 'Vendor', 'vendor_name' => 'Vendor',
'entity_state' => 'State', 'entity_state' => 'State',
'payment_status_name' => 'Status',
'client_created_at' => 'Date Created', 'client_created_at' => 'Date Created',
'postmark_error' => 'There was a problem sending the email through Postmark: :link', 'postmark_error' => 'There was a problem sending the email through Postmark: :link',
'project' => 'Project', 'project' => 'Project',

View File

@ -219,6 +219,7 @@
->setUrl(url('api/activities/'. $client->public_id)) ->setUrl(url('api/activities/'. $client->public_id))
->setCustomValues('entityType', 'activity') ->setCustomValues('entityType', 'activity')
->setCustomValues('clientId', $client->public_id) ->setCustomValues('clientId', $client->public_id)
->setCustomValues('rightAlign', [2, 3])
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
->setOptions('bFilter', false) ->setOptions('bFilter', false)
->setOptions('aaSorting', [['0', 'desc']]) ->setOptions('aaSorting', [['0', 'desc']])

View File

@ -59,19 +59,19 @@
} }
}, },
"bAutoWidth": false, "bAutoWidth": false,
@if (isset($hasCheckboxes) && $hasCheckboxes)
// Disable sorting on the first column
"aoColumnDefs": [ "aoColumnDefs": [
@if (isset($hasCheckboxes) && $hasCheckboxes)
// Disable sorting on the first column
{ {
'bSortable': false, 'bSortable': false,
'aTargets': [ 0, {{ count($columns) - 1 }} ] 'aTargets': [ 0, {{ count($columns) - 1 }} ]
}, },
@endif
{ {
'sClass': 'right', 'sClass': 'right',
'aTargets': {{ isset($values['rightAlign']) ? json_encode($values['rightAlign']) : '[]' }} 'aTargets': {{ isset($values['rightAlign']) ? json_encode($values['rightAlign']) : '[]' }}
} }
], ],
@endif
@foreach ($options as $k => $o) @foreach ($options as $k => $o)
{!! json_encode($k) !!}: {!! json_encode($o) !!}, {!! json_encode($k) !!}: {!! json_encode($o) !!},
@endforeach @endforeach

View File

@ -65,7 +65,6 @@
{!! Datatable::table() {!! Datatable::table()
->addColumn(Utils::trans($datatable->columnFields(), $datatable->entityType)) ->addColumn(Utils::trans($datatable->columnFields(), $datatable->entityType))
->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : (isset($vendorId) ? $vendorId : '')))) ->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : (isset($vendorId) ? $vendorId : ''))))
->setCustomValues('rightAlign', isset($rightAlign) ? $rightAlign : [])
->setCustomValues('entityType', Utils::pluralizeEntityType($entityType)) ->setCustomValues('entityType', Utils::pluralizeEntityType($entityType))
->setCustomValues('clientId', isset($clientId) && $clientId) ->setCustomValues('clientId', isset($clientId) && $clientId)
->setOptions('sPaginationType', 'bootstrap') ->setOptions('sPaginationType', 'bootstrap')
@ -108,6 +107,23 @@
{!! Former::close() !!} {!! Former::close() !!}
<style type="text/css">
@foreach ($datatable->rightAlignIndices() as $index)
.listForm_{{ $entityType }} table.dataTable td:nth-child({{ $index }}) {
text-align: right;
}
@endforeach
@foreach ($datatable->centerAlignIndices() as $index)
.listForm_{{ $entityType }} table.dataTable td:nth-child({{ $index }}) {
text-align: center;
}
@endforeach
</style>
<script type="text/javascript"> <script type="text/javascript">
function submitForm_{{ $entityType }}(action, id) { function submitForm_{{ $entityType }}(action, id) {