I work on jQuery with asp.net . I face issue I can't remove row from grid view based on key AUD_RECID and P_BUDGET_YEAR .
AUD_RECID with different P_BUDGET_YEAR so I need key will be both from AUD_RECID and P_BUDGET_YEAR
SO I will have unique Value when remove row and it will remove it success based on key contain both (AUD_RECID,P_BUDGET_YEAR)
I can't add P_BUDGET_YEAR with AUD_RECID to be one key for remove this is my issue .
code below working when remove based on AUD_RECID so
my modification need add P_BUDGET_YEAR with AUD_RECID to be as key when delete
what I try as below
1- When press delete row on every row on grid view .
function ADD_AUDITORWithComplain() {
var AUD_RECID = $("#ddlP_AUDITORS_CURInfo").val();
var AUD_DESC = $("#ddlP_AUDITORS_CURInfo option:selected").text();
var P_BUDGET_YEAR = $("#ddlP_BUDGET_YEAR_CUR option:selected").text();
$.ajax({
data: "{'AUD_RECID':'" + AUD_RECID +
"','AUD_DESC':'" + AUD_DESC +
"','P_BUDGET_YEAR':'" + P_BUDGET_YEAR +
"'}",
dataType: "json",
success: function (Result) {
CloseLoading();
$.each(Result.d, function (key, value) {
if (value.Status == "1") {
if (value.ADDED_AUDITORS_INFO != null) {
if (value.ADDED_AUDITORS_INFO.length > 0) {
$("#gvP_AUDITORS").empty();
var rowNo = 1;
for (var i in value.ADDED_AUDITORS_INFO) {
if (rowNo == 1) {
$("#gvP_AUDITORS").append("? ????? ???????? ????? ??????? ");
}
var row = " " + "" +
(rowNo) + " " +
value.ADDED_AUDITORS_INFO[i].AUD_DESC + " " + value.ADDED_AUDITORS_INFO[i].P_BUDGET_YEAR + " " +
" ???" +
" ";
row = $(row).hide();
$('#gvP_AUDITORS').append($(row));
rowNo++;
$(row).fadeIn(1000);
}
}
}
$("#ddlP_AUDITORS_CURInfo").val('').trigger("chosen:updated");
ModelSuccessDanger('????? ?????', value.StatusDesc, '1', null);
}
else {
ModelSuccessDanger('???? !!', value.StatusDesc, '0', null);
}
});
}
});
}
2- when click yes or no for confirm dialog
function DELETE_AUDITOR_CONFIRM_COMPLAIN(AUD_RECID, P_BUDGET_YEAR,
title, message) {
if (custom_confirm(title, message, (ans) => {
if (ans) {
DELETE_AUDITOR_COMPLAIN(AUD_RECID, P_BUDGET_YEAR);
return true;
} else {
return false;
}
}) == true) {
return true;
}
else {
return false;
}
}
3- WHEN change id for delete I need to be based on AUD_RECID and P_BUDGET_YEAR
function DELETE_AUDITOR_COMPLAIN(AUD_RECID, P_BUDGET_YEAR) {
$.ajax({
contentType: "application/json; charset=utf-8",
data: "{'AUD_RECID':'" + AUD_RECID +
"','P_BUDGET_YEAR':'" + P_BUDGET_YEAR +
"'}",
dataType: "json",
success: function (Result) {
CloseLoading();
$.each(Result.d, function (key, value) {
if (value.Status == "1") {
if (AUD_RECID == "") {
$("#gvP_AUDITORS").empty();
}
else {
var btnDeleteID = AUD_RECID;
var record_id = $('#' + btnDeleteID).attr("id");
var tr_id = $('#' + btnDeleteID).parents(".record");
tr_id.css("background-color", "#F2DEDE");
tr_id.fadeOut(500, function () {
//Remove GridView row
tr_id.remove();
totalRows = $("#gvP_AUDITORS tr").length;
if (totalRows < 2) {
$("#gvP_AUDITORS").empty();
}
var i = 1;
$('#gvP_AUDITORS > tr > .tdCount').each(function () {
$(this).text(i);
i++;
});
});
}
//ModelSuccessDanger('????? ?????', value.StatusDesc, '1', null);
}
else {
ModelSuccessDanger('???? !!', value.StatusDesc, '0', null);
}
});
}
});
}
Vikas SinghPosted May 24, 2024, 4:12 AM
To modify your jQuery code to use both
AUD_RECIDandP_BUDGET_YEARas the key when removing rows from the grid view, you need to adjust the way you set theidattribute of the row and how you select the row for deletion. Here’s how you can achieve that:Set a combined key for the row
idattribute:idattribute of the row to include bothAUD_RECIDandP_BUDGET_YEAR.Update the delete function to use the combined key:
Here’s your modified code:
Step 1: Adding Rows with Combined Key
Update the code in
ADD_AUDITORWithComplainto set theidattribute of each row using a combination ofAUD_RECIDandP_BUDGET_YEAR.function ADD_AUDITORWithComplain() {
var AUD_RECID = $("#ddlP_AUDITORS_CURInfo").val();
var AUD_DESC = $("#ddlP_AUDITORS_CURInfo option:selected").text();
var P_BUDGET_YEAR = $("#ddlP_BUDGET_YEAR_CUR option:selected").text();
$.ajax({
data: JSON.stringify({
AUD_RECID: AUD_RECID,
AUD_DESC: AUD_DESC,
P_BUDGET_YEAR: P_BUDGET_YEAR
}),
dataType: "json",
success: function (Result) {
CloseLoading();
$.each(Result.d, function (key, value) {
if (value.Status == "1") {
if (value.ADDED_AUDITORS_INFO != null && value.ADDED_AUDITORS_INFO.length > 0) {
$("#gvP_AUDITORS").empty();
var rowNo = 1;
for (var i in value.ADDED_AUDITORS_INFO) {
if (rowNo == 1) {
$("#gvP_AUDITORS").append("
}
var combinedId = value.ADDED_AUDITORS_INFO[i].AUD_RECID + "_" + value.ADDED_AUDITORS_INFO[i].P_BUDGET_YEAR;
var row = "
"
"
"
"
"Are you sure you want to delete?\", \"" + "Are you sure you want to delete auditor: " + value.ADDED_AUDITORS_INFO[i].AUD_DESC + " for budget year: " + value.ADDED_AUDITORS_INFO[i].P_BUDGET_YEAR + "\"); return false;' " +
"data-toggle='tooltip' title='" + value.ADDED_AUDITORS_INFO[i].AUD_DESC + "'>Delete
row = $(row).hide();
$('#gvP_AUDITORS').append($(row));
rowNo++;
$(row).fadeIn(1000);
}
}
$("#ddlP_AUDITORS_CURInfo").val('').trigger("chosen:updated");
ModelSuccessDanger('Success', value.StatusDesc, '1', null);
} else {
ModelSuccessDanger('Error !!', value.StatusDesc, '0', null);
}
});
}
});
}
Step 2: Update Delete Function to Use Combined Key
Update
DELETE_AUDITOR_COMPLAINandDELETE_AUDITOR_CONFIRM_COMPLAINfunctions to handle the combined key:function DELETE_AUDITOR_CONFIRM_COMPLAIN(AUD_RECID, P_BUDGET_YEAR, title, message) {
if (custom_confirm(title, message, (ans) => {
if (ans) {
DELETE_AUDITOR_COMPLAIN(AUD_RECID, P_BUDGET_YEAR);
return true;
} else {
return false;
}
}) == true) {
return true;
} else {
return false;
}
}
function DELETE_AUDITOR_COMPLAIN(AUD_RECID, P_BUDGET_YEAR) {
$.ajax({
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
AUD_RECID: AUD_RECID,
P_BUDGET_YEAR: P_BUDGET_YEAR
}),
dataType: "json",
success: function (Result) {
CloseLoading();
$.each(Result.d, function (key, value) {
if (value.Status == "1") {
if (AUD_RECID == "") {
$("#gvP_AUDITORS").empty();
} else {
var combinedId = AUD_RECID + "_" + P_BUDGET_YEAR;
var tr_id = $('#tr' + combinedId);
tr_id.css("background-color", "#F2DEDE");
tr_id.fadeOut(500, function () {
tr_id.remove();
var totalRows = $("#gvP_AUDITORS tr").length;
if (totalRows < 2) {
$("#gvP_AUDITORS").empty();
}
var i = 1;
$('#gvP_AUDITORS > tr > .tdCount').each(function () {
$(this).text(i);
i++;
});
});
}
} else {
ModelSuccessDanger('Error !!', value.StatusDesc, '0', null);
}
});
}
});
}
This ensures that each row can be uniquely identified and deleted based on both
AUD_RECIDandP_BUDGET_YEAR.