Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Sort the table td having same text in jquery or javascript without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I need to get an idea how we can sort the table having the same text in td
e.g I have a below table
Column 1 Column 2 A test1 B test2 C test3 D test1 E test4 F test3
I want an output something like below
Column 1 Column 2 A test1 D test1 C test3 F test3 B test2 E test4
Why I want to sort it in this way so that I can do the rowspan easily
Answer
DEMO http://jsbin.com/sowudefaho/edit?html,css,js,output
$('tbody tr').sort(function(a, b) { var aText = $(a).find('td:eq(1)').text(); var bText = $(b).find('td:eq(1)').text(); if (aText > bText){ return 1; } else if (aText < bText){ return -1; } return 0; }).appendTo('tbody');
you can sort the table column using sort function
We are here to answer your question about Sort the table td having same text in jquery or javascript - If you find the proper solution, please don't forgot to share this with your team members.