I'm working on project here i'm facing issue, i have created jquery table and on checkbox checked get all the values of specific row and push it into array now i want to remove each row record from array when i unchecked that row, i have written some script for remove but it doesn't work properly. And also tell me that is there any easy way to get data of specific row with checkbox in jqury table. Script
$.ajax({
type: 'POST',
url: "/Student/GetFee",
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: JSON.stringify({ Class_Id: Class_Id }),
success: function (list) {
$("#view").html('');
$.each(list, function (key, value) {
var html = $(
'<tr>' +
'<td>' + value.Id + '</td>' +
'<td>' + value.FeeHeadName + '</td>' +
'<td>' + value.SchoolName + '</td>' +
'<td>' + value.ClassName + '</td>' +
'<td>' + value.Amount + '</td>' +
'<td>' + "<input type='text' name='Paid' class='paid' onkeypress='paid(this)'/>" + '</td>' +
'<td>' + "<input type='text' class='Discount' name='Discount' onkeypress='discount(this)'/>" + '</td>' +
'<td>' + "<input type='text' class='NetAmount' name='NetAmount' />" + '</td>' +
'<td>' + "<input type='checkbox' class='ckb'/>" + '</td>' +
'</tr>');
$("#view").append(html);
html = '';
});
//pushing objects in array
$('#view input[type=checkbox]').click(function () {
var row = $(this).closest('tr');
var id = row.find('td:eq(0)').text();
var fname = row.find('td:eq(1)').text();
var sname = row.find('td:eq(2)').text();
var cname = row.find('td:eq(3)').text();
var amount = row.find('td:eq(4)').text();
var paid = row.find($('.paid')).val();
var discount = row.find($('.Discount')).val();
var netAmount = row.find($('.NetAmount')).val();
if ($(this).is(":checked")) {
info.push({
Fee_Id: id,
FeeHeadName: fname,
sname: sname,
cname: cname,
Amount: amount,
Paid: paid,
Discount: discount,
NetAmount: netAmount
});
console.log(info);
}
else {
if ($(this).not(":checked")) {
var x = info.indexOf($(this).val());
info.splice(x, 1);
console.log(info);
}
}
});
}
});
Aucun commentaire:
Enregistrer un commentaire