I'm working with the datatables, and by chance I decided to use the function ajax
of it, I did the whole process, but one thing is missing, I can reorder the array, because using processing server-side
dataTables
does not interact client-side
to reorder.
The returned array is a JSON
of this (here it is in order, but I need to be able to change that order as I want):
$arr = [
[
'linha 1 coluna 1 valor z',
'linha 1 coluna 2 valor b',
'linha 1 coluna 3 valor h',
'linha 1 coluna 4 valor d',
'linha 1 coluna 5 valor e'
],
[
'linha 2 coluna 1 valor b',
'linha 2 coluna 2 valor c',
'linha 2 coluna 3 valor r',
'linha 2 coluna 4 valor i',
'linha 2 coluna 5 valor l'
],
[
'linha 3 coluna 1 valor q',
'linha 3 coluna 2 valor w',
'linha 3 coluna 3 valor y',
'linha 3 coluna 4 valor u',
'linha 3 coluna 5 valor s'
]
];
What I need is to be able to sort the row by the value of any of the columns based on the value it has itself.
I am not able to find the function that I can do this, well it is this doubt:
How to sort an array when there is no index and the value is its own index of the second dimension?
Example of what it would look like if I were given the command to sort by column 1:
$arr = [
[
'linha 2 coluna 1 valor b',
'linha 2 coluna 2 valor c',
'linha 2 coluna 3 valor r',
'linha 2 coluna 4 valor i',
'linha 2 coluna 5 valor l'
],
[
'linha 3 coluna 1 valor q',
'linha 3 coluna 2 valor w',
'linha 3 coluna 3 valor y',
'linha 3 coluna 4 valor u',
'linha 3 coluna 5 valor s'
],
[
'linha 1 coluna 1 valor z',
'linha 1 coluna 2 valor b',
'linha 1 coluna 3 valor h',
'linha 1 coluna 4 valor d',
'linha 1 coluna 5 valor e'
]
];
UPDATE
I was able to play a game, but I still think there should be a better way:
$ ordergin = $ var ['order_rule'];
foreach ($records['data'] as $key => $row) {
$order_company[$key] = $row[1];
$order_cnpj[$key] = $row[2];
$order_tax_regime[$key] = $row[3];
$order_responsible[$key] = $row[3];
$order_status[$key] = $row[5];
}
if ($ordering == 'order_by_resp_desc') {
array_multisort($order_responsible, SORT_DESC, $records['data']);
} elseif($ordering == 'order_by_resp_asc'){
array_multisort($order_responsible, SORT_ASC, $records['data']);
}
//Seguindo daqui até todas as opções disponiveis de ordenamento