Click here to Skip to main content
15,916,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to sort by key in html table in JS

For ex: My table
Column 1     column2
    A	     vini
    B	     Kiru
    c	     vini
    D        Loki

if my key word is vini

then result should be in this way (i.e first rows should be the key word and followed by other words)
Column 1     column2
    A	     vini
    c	     vini
    B	     kiru
    D        Loki 

please help me
Posted
Updated 10-May-12 19:13pm
v2
Comments
Sandeep Mewara 11-May-12 1:42am    
Is doing this sorting before binding the data an option for you?
vinu.1111 11-May-12 2:23am    
no after binding a table i'm giving a key word
based on that again it should bind as the above example
vinu.1111 11-May-12 3:08am    
Alternate solution to the previous question
how to filter html table by not deleting the remaining rows in table
vinu.1111 11-May-12 3:10am    
i have the the javascript for filter but it will delete's the remaining rows

function filter(term, _id, cellNr) {
var suche = term.value.toLowerCase();
var table = document.getElementById(_id);
var ele;
for (var r = 1; r < table.rows.length; r++) {
ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
if (ele.toLowerCase().indexOf(suche) >= 0) {
table.rows[r].style.display = '';
}
else {
table.rows[r].style.display = 'none';
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900