Answer the question
In order to leave comments, you need to log in
How to sort div elements?
Hello.
There is an html page. It has a table. But the table is unusual, formed from div with table display
Something like this
<div id="table">
<div class="table_header">
<div class="th">Артикул</div>
<div class="th">Название</div>
<div class="th">цена</div>
</div>
<div class="tr">
<div class="td column1">3333333</div>
<div class="td column2">Бла бла бла</div>
<div class="td column3">150</div>
</div>
<div class="tr">
<div class="td column1">2222</div>
<div class="td column2">Бла бла бла</div>
<div class="td column3">250</div>
</div>
<div class="tr">
<div class="td column1">151515</div>
<div class="td column2">Бла бла бла</div>
<div class="td column3">350</div>
</div>
</div>
function sortList(artikul){
var rows=$.makeArray($('div.tr')); //тут у нас будут все поля таблицы
var e= rows.sort(function(a, b){
//если артикул в данном ряде есть
if(artikul==$(a).find('div.col1umn1').text()){
return 1;
}else{
return -1;
}
});
//возвращаем сортированный массив
return e;
}
Answer the question
In order to leave comments, you need to log in
Perhaps there is a more elegant way to solve this problem?Of course you can. It is enough to understand that you do not need to sort the rows of the table, but the data . And then render the data.
If you use a regular table, then the browser either starts to slow down, or even crashes. As far as I know, this is due to increased memory consumption and processor load when displaying and calculating the table. This doesn't happen with divs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question