I'm trying to get the desired order for the datatable columns.
I have tried these two solutions which i got through datatable documents. https://datatables.net/extensions/rowreorder/examples/initialisation/restrictedOrdering.html https://datatables.net/reference/option/columnDefs.targets But none of them worked for me.
This is just a overview of the table how it looks like : https://app.hyfy.io/v/abz9KaAAzan/ Check this screenshot : https://prnt.sc/n92d03 (This is the problem I'm facing now) So every unallocated category td is coming right after the first category(refers to third column) in every asset (refers to second column) and this unallocated column I'm adding at front end using if condition. Now I'm getting the correct order for second column(made this order at backend query) how client wants, but unallocated is coming in the wrong place. If I add ordering for third column for this datatable, the second column order is getting changed.
Datatable jquery:
// "ordering": false,
"scrollY": "650px",
"paging": false,
'rowsGroup': [0, 1],
scrollX: true,
fixedColumns: {
leftColumns: 3
},
"order": [
[2, "asc"]
],
"aoColumnDefs": [{
'bSortable': false,
'aTargets': ['nosort']
}]
});
Result Array:
Array
(
[0] => Array
(
[id] => 25
[asset_id] => 4
[description] => PL31
[created_at] => 2017-08-17 13:40:48
[updated_at] => 2017-08-17 13:40:48
[status] => 1
[cost_code] => P0030
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 4
[name] => 0.35m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:26
[updated_at] => 2018-06-12 17:26:52
[status] => 1
[weekday_am] => 165
[weekday_pm] => 165
[weekend_am] => 165
[weekend_pm] => 165
[group_id] => 3
[cost_weekday_am] => 132
[cost_weekend_am] => 132
[cost_weekend_pm] => 132
[cost_weekday_pm] => 132
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[1] => Array
(
[id] => 26
[asset_id] => 4
[description] => PL32
[created_at] => 2017-08-17 13:40:51
[updated_at] => 2017-08-17 13:40:51
[status] => 1
[cost_code] => P0031
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 4
[name] => 0.35m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:26
[updated_at] => 2018-06-12 17:26:52
[status] => 1
[weekday_am] => 165
[weekday_pm] => 165
[weekend_am] => 165
[weekend_pm] => 165
[group_id] => 3
[cost_weekday_am] => 132
[cost_weekend_am] => 132
[cost_weekend_pm] => 132
[cost_weekday_pm] => 132
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[2] => Array
(
[id] => 156
[asset_id] => 4
[description] => PL33
[created_at] => 2017-11-14 14:56:52
[updated_at] => 2017-11-14 14:56:52
[status] => 1
[cost_code] => P0032
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 4
[name] => 0.35m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:26
[updated_at] => 2018-06-12 17:26:52
[status] => 1
[weekday_am] => 165
[weekday_pm] => 165
[weekend_am] => 165
[weekend_pm] => 165
[group_id] => 3
[cost_weekday_am] => 132
[cost_weekend_am] => 132
[cost_weekend_pm] => 132
[cost_weekday_pm] => 132
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[3] => Array
(
[id] => 27
[asset_id] => 5
[description] => PL51
[created_at] => 2017-08-17 13:41:19
[updated_at] => 2017-08-17 13:41:19
[status] => 1
[cost_code] => P0033
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 5
[name] => 0.5m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:45
[updated_at] => 2018-06-12 17:26:23
[status] => 1
[weekday_am] => 190
[weekday_pm] => 190
[weekend_am] => 190
[weekend_pm] => 190
[group_id] => 3
[cost_weekday_am] => 152
[cost_weekend_am] => 152
[cost_weekend_pm] => 152
[cost_weekday_pm] => 152
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[4] => Array
(
[id] => 28
[asset_id] => 5
[description] => PL53
[created_at] => 2017-08-17 13:41:22
[updated_at] => 2017-08-17 13:41:22
[status] => 1
[cost_code] => P0034
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 5
[name] => 0.5m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:45
[updated_at] => 2018-06-12 17:26:23
[status] => 1
[weekday_am] => 190
[weekday_pm] => 190
[weekend_am] => 190
[weekend_pm] => 190
[group_id] => 3
[cost_weekday_am] => 152
[cost_weekend_am] => 152
[cost_weekend_pm] => 152
[cost_weekday_pm] => 152
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[5] => Array
(
[id] => 29
[asset_id] => 5
[description] => PL54
[created_at] => 2017-08-17 13:41:25
[updated_at] => 2017-08-17 13:41:25
[status] => 1
[cost_code] => P0035
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 5
[name] => 0.5m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:41:45
[updated_at] => 2018-06-12 17:26:23
[status] => 1
[weekday_am] => 190
[weekday_pm] => 190
[weekend_am] => 190
[weekend_pm] => 190
[group_id] => 3
[cost_weekday_am] => 152
[cost_weekend_am] => 152
[cost_weekend_pm] => 152
[cost_weekday_pm] => 152
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 0000-00-00
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
[6] => Array
(
[id] => 30
[asset_id] => 6
[description] => PL12
[created_at] => 2017-08-17 13:41:40
[updated_at] => 2017-08-17 13:41:40
[status] => 1
[cost_code] => P0036
[weight] => 0.00
[deleted_at] =>
[active_from] => 0000-00-00
[inactive_from] => 0000-00-00
[asset] => Array
(
[id] => 6
[name] => 1m Planer
[default_rate] =>
[tax_id] => 1
[nominal_code] => 00002
[created_at] => 2017-07-24 20:42:06
[updated_at] => 2019-02-12 18:38:20
[status] => 1
[weekday_am] => 309.31
[weekday_pm] => 309.31
[weekend_am] => 309.31
[weekend_pm] => 309.31
[group_id] => 3
[cost_weekday_am] => 247.45
[cost_weekend_am] => 247.45
[cost_weekend_pm] => 247.45
[cost_weekday_pm] => 247.45
[project_code] =>
[manufacturer] =>
[model] =>
[purchase_date] => 1970-01-01
[warranty_expiry] =>
[mot_due] =>
[group] => Array
(
[id] => 3
[name] => Planers
[status] => 1
[created_at] => 2017-07-14 17:21:49
[updated_at] => 2017-07-14 17:21:49
)
)
[asset_id_allocations] => Array
(
)
)
)
Blade code:
@php $asset_category_id = 0; @endphp
@foreach($asset_array as $key=>$final)
<tr>
normal row
</tr>
@if($asset_category_id != trim($final['asset']['id']))
<tr>
Unallocated row
</tr>
@endif
@php $asset_category_id = $final['asset']['id']; @endphp
@endforeach
Any suggestions to get this solved?