I have integrated add row and delete row functionality in my table. If i add row second row number is also 1. I need to change number of each row
as per every add and delete like 1, 2 etc.
I used the code from this fiddle /.
How to achieve this? Any help would be appreciated. Thanks.
I have integrated add row and delete row functionality in my table. If i add row second row number is also 1. I need to change number of each row
as per every add and delete like 1, 2 etc.
I used the code from this fiddle http://jsfiddle/MJGV2/6/.
How to achieve this? Any help would be appreciated. Thanks.
Share Improve this question edited Mar 29, 2014 at 12:35 Shaik Riyaz 11.5k7 gold badges55 silver badges72 bronze badges asked Mar 29, 2014 at 12:20 marswebmarsweb 1871 gold badge2 silver badges12 bronze badges3 Answers
Reset to default 7You can add this:
var renum = 1;
$("tr td strong").each(function() {
$(this).text(renum);
renum++;
});
See this Fiddle demo.
There are a lot of errors in your code - for example all id
needs to be unique and you should fix this.
For example, you can add call recalculate
function, like this:
function recalculate() {
var i = 1;
$(".numberRow").each(function() {
$(this).find("strong").text(i++);
});
}
Where numberRow
is css class on td, where store number of row.
I add this in your jsfiddle example
There were lot of things missing in your code. i have tuned everything properly
JS CODE:
$("input[type='button'].AddRow").on('click',
function () {
if ($(this).val() == 'Delete') {
trSet = $(this).closest('tr').nextAll();
currIndex = $(this).closest('tr').find('td span').html();
$(this).closest('tr').remove();
trSet.each(function () {
$(this).find('td span').html(currIndex);
currIndex++;
});
count = currIndex - 1;
} else {
var $tr = $(this).closest('tr').clone(true);
var $input = $tr.find('input.startdatum');
++count;
$tr.find('td span').html(count);
$(this).val('Delete');
var id = 'datepicker' + count;
$input.attr('id', id).data('index', count);
console.log(count);
$tr.appendTo($(this).closest('table'));
setdatepicker();
}
});
LIVE DEMO:
http://jsfiddle/MJGV2/14/
Happy Coding :)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745468736a4629034.html
评论列表(0条)