-1

I have div's like below

<div class="header">
<div class="name">Name</div>
<div class="status">Status</div>
<div class="message">This is a testing</div>
</div>


<div class="container">
<div class="name">dynamic value comes from DB</div>
<div class="status">dynamic value comes from DB</div>
<div class="Message">dynamic value from DB</div>
</div>

I need to sort above structure by clicking Name or Status div header and it should sort data accordingly.

Kindly help me with this.

AB Udhay
  • 643
  • 4
  • 9
Vilayat Ali
  • 1
  • 1
  • 1
  • so, there's multiple "container" divs? at the moment, there's nothing to sort – Jaromanda X Oct 04 '17 at 05:23
  • `help me with this` glad to help, it's actually very very easy, what have you done so far besides describing the requirement? – Jaromanda X Oct 04 '17 at 05:37
  • Thank you for your response. I have tried to use jquery but didn't work. $('.classname').click(function(){ var elem = $('#container').find('div').sort(sortClass); $('#container').append(elem); }); function sortClass(a, b) { return a.className < b.className; } – Vilayat Ali Oct 04 '17 at 10:01

1 Answers1

0

You can prepare a json array of object with key value pair. Eg. [{"name":"xyz", "status":"available"}] Sort it and rebind with dynamic html. Follow below linkSort json

AB Udhay
  • 643
  • 4
  • 9