Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Is there a way to group by one column for dynamically pulled values without the need for a trigger function?

I've been trying to implement this script which pulls values from another page and sorts them into a table alphabetically. The three values are Name - City - District. The script works perfectly. But on top of that, I would like the script to group the values by city. So instead of:

--Name -- City -- District --
Name1 -- London -- Kingsroad
Name3 -- London -- Westminster
Name4 -- Birmingham -- Yardley

I'd like for it to be organized as below, with the city column spanning 2 columns.

------ Birmingham -----
Name4 -- Yardley
------ London -----
Name1 -- Kingsroad
Name3 -- Westminster

The script I've used to pull values is this:


var fhold =$("#List");


$.get("/memberlist", function(data) {

$('.mem-info',data).each(function(){
 fhold.append($(this));
 

});

 var items = fhold.children('.mem-info').get();

items.sort(function(a, b) {
  return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
});
 
 fhold.append(items);
 
});
});

Here's the HTML for the same:

<table id="List" class="display"><tbody>
<tr> <td>Name</td> <td>City</td><td>District</td> </tr>
</tbody>
</table>

So again, so far, it works fine. But I want it to group by city. I've tried using this fix here (https://datatables.net/examples/advanced_init/row_grouping.html) but I believe it only works for static values. I've looked into grouping values dynamically but most fixes say that a click function is required.

Is there a way to do so without a click/event function? Any help would be appreciated. Much thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use lodash's groupby method

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>

You can get a reference from following link lodash groupby-method

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!