admin管理员组文章数量:1023895
I have a table. see my table structure
<table width="100%" border="1">
<tr>
<td width="2%"><h2># SL NO</h2></td>
<td width="70%"><h2>Name</h2></td>
<td width="15%"><h2>Edit</h2></td>
<td width="13%"><h2>Delete</h2></td>
</tr>
<tr id="id0">
<td >1</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td width="13%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(0)" /></a></td>
</tr>
<tr id="id1">
<td>2</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(1)" /></a></td>
</tr>
... .... ..
When press on the delete button i need to hide that row I have used this to remove particular row from the table
$("#id" + i).remove();
Its working fine. But the serial number... i's display as wrong. I.e. when I delete second row the serial number with in the third row is still 3
I need to display this s 2 and so on...
I there is any way to do this in jquery Thanks in advance
I have a table. see my table structure
<table width="100%" border="1">
<tr>
<td width="2%"><h2># SL NO</h2></td>
<td width="70%"><h2>Name</h2></td>
<td width="15%"><h2>Edit</h2></td>
<td width="13%"><h2>Delete</h2></td>
</tr>
<tr id="id0">
<td >1</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td width="13%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(0)" /></a></td>
</tr>
<tr id="id1">
<td>2</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(1)" /></a></td>
</tr>
... .... ..
When press on the delete button i need to hide that row I have used this to remove particular row from the table
$("#id" + i).remove();
Its working fine. But the serial number... i's display as wrong. I.e. when I delete second row the serial number with in the third row is still 3
I need to display this s 2 and so on...
I there is any way to do this in jquery Thanks in advance
Share Improve this question edited Apr 5, 2012 at 11:01 yunzen 33.5k13 gold badges78 silver badges113 bronze badges asked Apr 5, 2012 at 10:15 user1263260user1263260 2433 gold badges6 silver badges18 bronze badges 1- Can you explain your problem a way everybody will understand? (I can't see your problem (maybe my bad english?)) – user1150525 Commented Apr 5, 2012 at 10:23
3 Answers
Reset to default 3function fnDeleteState(i) {
$("#id" + i).remove();
$("tr").each(function (index) { // traverse through all the rows
if(index != 0) { // if the row is not the heading one
$(this).find("td:first").html(index + ""); // set the index number in the first 'td' of the row
}
});
}
If I understand correctly, you need to update the first cell of each row so they display the rank of the row.
You can achieve it by adding a class for each of your content row, for example "contentrow" (to distinguish them from the heading row) and then write a function like this:
function refreshRowIDs(){
$(".contentrow").each(function(index){
$(this).children("td:first").html(index);
});
}
You need to reorder the Serial no. after deletion . You can use something like this :
function reorder(){
var i = 1;
$('#tableid tr').each(function() {
$(this).find("td:first").text(i);
i++;
});
}
I have a table. see my table structure
<table width="100%" border="1">
<tr>
<td width="2%"><h2># SL NO</h2></td>
<td width="70%"><h2>Name</h2></td>
<td width="15%"><h2>Edit</h2></td>
<td width="13%"><h2>Delete</h2></td>
</tr>
<tr id="id0">
<td >1</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td width="13%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(0)" /></a></td>
</tr>
<tr id="id1">
<td>2</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(1)" /></a></td>
</tr>
... .... ..
When press on the delete button i need to hide that row I have used this to remove particular row from the table
$("#id" + i).remove();
Its working fine. But the serial number... i's display as wrong. I.e. when I delete second row the serial number with in the third row is still 3
I need to display this s 2 and so on...
I there is any way to do this in jquery Thanks in advance
I have a table. see my table structure
<table width="100%" border="1">
<tr>
<td width="2%"><h2># SL NO</h2></td>
<td width="70%"><h2>Name</h2></td>
<td width="15%"><h2>Edit</h2></td>
<td width="13%"><h2>Delete</h2></td>
</tr>
<tr id="id0">
<td >1</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td width="13%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(0)" /></a></td>
</tr>
<tr id="id1">
<td>2</td>
<td>XXXXXXX</td>
<td><a href="#"><img src="../images/icon_edit.gif" alt="Edit" /></a></td>
<td%"><a href="#"><img src="../images/delete_07.png" alt="Delete" onclick="fnDeleteState(1)" /></a></td>
</tr>
... .... ..
When press on the delete button i need to hide that row I have used this to remove particular row from the table
$("#id" + i).remove();
Its working fine. But the serial number... i's display as wrong. I.e. when I delete second row the serial number with in the third row is still 3
I need to display this s 2 and so on...
I there is any way to do this in jquery Thanks in advance
Share Improve this question edited Apr 5, 2012 at 11:01 yunzen 33.5k13 gold badges78 silver badges113 bronze badges asked Apr 5, 2012 at 10:15 user1263260user1263260 2433 gold badges6 silver badges18 bronze badges 1- Can you explain your problem a way everybody will understand? (I can't see your problem (maybe my bad english?)) – user1150525 Commented Apr 5, 2012 at 10:23
3 Answers
Reset to default 3function fnDeleteState(i) {
$("#id" + i).remove();
$("tr").each(function (index) { // traverse through all the rows
if(index != 0) { // if the row is not the heading one
$(this).find("td:first").html(index + ""); // set the index number in the first 'td' of the row
}
});
}
If I understand correctly, you need to update the first cell of each row so they display the rank of the row.
You can achieve it by adding a class for each of your content row, for example "contentrow" (to distinguish them from the heading row) and then write a function like this:
function refreshRowIDs(){
$(".contentrow").each(function(index){
$(this).children("td:first").html(index);
});
}
You need to reorder the Serial no. after deletion . You can use something like this :
function reorder(){
var i = 1;
$('#tableid tr').each(function() {
$(this).find("td:first").text(i);
i++;
});
}
版权声明:本文标题:javascript - how to give continuous number for a Serial No. column within a table using jquery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745550894a2155626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论