How to specify only for the new added row in datatable?
How to specify only for the new added row in datatable?
ElyaNordin
Posts: 4Questions: 3Answers: 0
Currently I'm using forEach
that will execute the code for every row by row of the datatable. My problem now is, how can I execute the code only for a specific row that newly added and ignoring the previously added row?
function InStockk() {
_datatableData.forEach(function (rowData) {
var ID = rowData.ID;
var quantity = parseInt($("#txtQuantity" + ID).val(), 10);
if (!quantity) { quantity = 0; }
var id = $("#txtItem"+ID).select2("val");
console.log("stock id :" + id);
$.ajax({
url: "../WS/wsQuotation.asmx/GetStockInfo",
type: 'GET',
data: {
StockID: id ,
},
success: function (data) {
var json = JSON.parse(data);
var instock = parseFloat(json[0]["Inventory_Quantity"]);
$("#txtStock" + ID).val(instock - quantity);
},
error: function (xhr, status, error) {
alert(xhr.responseText + ": " + error);
}
});
});
}
This discussion has been closed.
Answers
Assuming you want to process the maximum ID
If you may not change the sequence of _datatableData this could work:
sorry the second post was wrong; forgot to delete the sorting code:
But why are you not using an event? Assuming you use Editor as well.
This would give you the ID of the row created:
https://editor.datatables.net/reference/event/create