Sort by database is not needed. The use of plug-ins has not led to anything good - the table has got a slant. Dan array. I form it in php
.
$row_section['cell'][$index] = array( 0, $tovar, $cnt, $productID, $arElement["PROPERTIES"]["CML2_ARTICLE"]["VALUE"], $arElement["PROPERTIES"]["BREND"]["VALUE"], $arElement["NAME"], $n, $arElement["PROPERTIES"]["CML2_DAYS_DELIVERY"]["VALUE"], $price ); $index=$index+1; $mas=json_encode($row_section,256);
I send to the server by clicking on the table header:
<thead> <tr> <th class="def-table-code"> <a href="<?=$url?>&sort=property_CML2_ARTICLE&method=<?=$method?>">ΠΠΎΠ΄</a> </th> <th class="def-table-manufacturer"> <a href="<?=$url?>&sort=property_BREND&method=<?=$method?>">ΠΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»Ρ</a> </th> <th class="def-table-title"> <a href="<?=$url?>&sort=NAME&method=<?=$method?>">ΠΠ°Π·Π²Π°Π½ΠΈΠ΅</a> </th> <!-- <th class="def-table-available"> <a href="<?=$url?>&sort=CATALOG_QUANTITY&method=<?=$method?>">ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ, ΡΡ.</a> </th> <th class="def-table-delivery"> <a href="<?=$url?>&sort=property_CML2_DAYS_DELIVERY&method=<?=$method?>">Π‘ΡΠΎΠΊ ΠΏΠΎΡΡΠ°Π²ΠΊΠΈ, Π΄Π½. </th> <th class="def-table-price">Π¦Π΅Π½Π°, ΡΡΠ±.</th> <th class="def-table-buy">Π ΠΊΠΎΡΠ·ΠΈΠ½Ρ</th> --> <th class="def-table-available sort_id" id="CATALOG_QUANTITY" onclick="cat(5,1);">ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ, ΡΡ.</th> <th class="def-table-delivery sort_id" id="property_CML2_DAYS_DELIVERY" onclick="cat(6,1);">Π‘ΡΠΎΠΊ ΠΏΠΎΡΡΠ°Π²ΠΊΠΈ, Π΄Π½.</th> <th class="def-table-price sort_id" id="CATALOG_PRICE" onclick="cat(7,1);">Π¦Π΅Π½Π°, ΡΡΠ±.</th> <th class="def-table-buy">Π ΠΊΠΎΡΠ·ΠΈΠ½Ρ</th> </tr> </thead>
I send ajax
request to the server:
function cat(sortby, method){ alert(sortby); alert(method); $.ajax({ url: '/unimann/ajax/sortfromcatalogajax.php?sortby='+sortby+'&method='+method type: 'POST', data: massiv, success: function(res) { $('#sort_tab').html(res); alert('Soxranenp!'); } }); }
On the server I plan:
$data= json_decode($_POST['massiv'],true);
It will turn out an array (on the server it was not possible to check, I do not know whether it went). The idea is to get such an array
Array ( [cell] => Array ( [0] => Array ( [0] => 1 [1] => 453852 [2] => TB215363 [3] => FENOX [4] => TB215363_Π΄ΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½ΠΈΠΉ!\ Audi 80/90/100 1.6-2.0D 86-91 [5] => 6 [6] => 1 [7] => 772.52 ) [1] => Array ( [0] => 1 [1] => 355471 [2] => 8DD 355 100-581 [3] => HELLA [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ AUDI 80 86>91/100 76>88 ΠΏΠ΅ΡΠ΅Π΄Π½ΠΈΠΉ Π½Π΅ Π²Π΅Π½Ρ. [5] => 2 [6] => 1 [7] => 1044.41 ) [2] => Array ( [0] => 1 [1] => 228617 [2] => 0986478016 [3] => BOSCH [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½ AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 6 [6] => 1 [7] => 1126.23 ) [3] => Array ( [0] => 1 [1] => 440468 [2] => 0986478016 [3] => BOSCH [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½ AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 2 [6] => 1 [7] => 1126.23 ) [4] => Array ( [0] => 1 [1] => 228618 [2] => 0986478016 [3] => BOSCH [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½ AUDI: 100 1.6/1.9/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9 82-91, 100 Avant 1.6/1. [5] => 2 [6] => 1 [7] => 1126.23 ) [5] => Array ( [0] => 1 [1] => 140741 [2] => BG2215 [3] => DELPHI [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ AUDI 80 86>91/100 76>88 ΠΏΠ΅ΡΠ΅Π΄Π½ΠΈΠΉ Π½Π΅ Π²Π΅Π½Ρ. [5] => 2 [6] => 1 [7] => 876.12 ) [6] => Array ( [0] => 1 [1] => 128269 [2] => A1081P [3] => LPR [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ AUDI 80 86>91/100 76>88 ΠΏΠ΅ΡΠ΅Π΄Π½ΠΈΠΉ Π½Π΅ Π²Π΅Π½Ρ. [5] => 2 [6] => 1 [7] => 1046.65 ) [7] => Array ( [0] => 1 [1] => 184737 [2] => 24.0113-0160.1 [3] => ATE [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo [5] => 4 [6] => 2 [7] => 1216.57 ) [8] => Array ( [0] => 1 [1] => 315459 [2] => 24.0113-0160.1 [3] => ATE [4] => ΠΠΈΡΠΊ ΡΠΎΡΠΌΠΎΠ·Π½ΠΎΠΉ ΠΏΠ΅ΡΠ΅Π΄Π½, AUDI: 100 1.6/1.9/2.0/2.0 D/2.1 76-82, 100 1.8/1.8 KAT/1.9/2.0 D/2.0 D Turbo [5] => 10 [6] => 1 [7] => 1216.57 ) ) )
Question: how to sort either cell[][5]
, or cell[][6]
, or cell[][7]
with respect to cell[][0]
and cell[][1]
? That is, we compare the elements for which cell[][1]
same, and sort them in ascending or descending order.