2
I am working with the datatables, and by chance of the destination I decided to use the function ajax
from it, I did the whole process, but one thing is missing, to be able to reorder the array, because using processing server-side
the dataTables
does not interact client-side
to reorder.
The returned array is a JSON
of that (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.
I’m not finding the function that I can do this, well it’s that doubt:
How to sort an array when there is no input and the value is the proper of the second dimension ?
Example of how it would look if I received 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'
]
];
UPDATING
I got it on a whim, but I still think there’s got to be a nicer 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
You can give an example of how this data would look after such an order?
– Woss
@Andersoncarloswoss put in the question there the example, I’m trying with array_multisort, but I still haven’t found the way
– AnthraxisBR