Мне было интересно, можно ли сортировать содержимое финальной таблицы, прежде чем вставлять ее в html, по значению столбца оплаты. Код формирования таблицы следующаяСортировка таблицы по значению столбца перед отображением jquery/js
function populateJobMarket() {
var tableContent = '';
$.getJSON('modalRoutes/jobmarket', function(data){
$.each(data, function() {
var cName = this.companyName;
$.each(this.hiring, function(){
tableContent += '<tr class=\'target_row\'>';
tableContent += '<td>' + cName + '</td>';
tableContent += '<td>' + this.paying + '</td>';
tableContent += '<td> <button type=\'button\' class=\'btn btn-warning job_apply\' id=' + this._id + '> Apply </button></td>';
tableContent += '</tr>';
});
});
$('#jobMarket_pp #joblist table tbody').html(tableContent); // Sort it before this step
});
}
HTML код:
<div class="modal fade" id="jobMarket_pp" tabindex="-1" role="dialog" aria-labelledby="jobMarket_pp">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="jobMarket_content" Job Offers</h4> </div> <div class="modal-body"> <div class='jobMarketAlert'></div>
<div id="joblist">
<table>
<thead>
<th>Company Name</th>
<th>Salary</th>
<th>Work</th>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
введите код html – AleshaOleg
@AleshaOleg вставляется html-код – Trax
@charlietfl Это даже не близко к этому. – Trax