I can create member objects using following html coding. But for some calculations, I need to get the count of the member objects. Also when I delete one of the member object it should reduce the member objects count.
Following fuction will create the members.
function appendMember(rowNumber) {
debugger
var subrowNumber = parseInt($("#itemmapWrapper" + rowNumber + "").attr("data-subrowNumber"));
subrowNumber = isNaN(subrowNumber) ? 1 : subrowNumber + 1;
var addNewItemDetailHtml = "<div class='col-lg-10 col-md-10 col-sm-10 col-xs-10 itemmapAllocationWrapper custom-paaddingnone form-group' \
id='dvaddNewItemDetailSub" + subrowNumber + "' data-subrowNumber='" + subrowNumber + "'>";
addNewItemDetailHtml += "<div class='col-lg-4 col-md-4 col-sm-4 col-xs-4 custom-paaddingnone'>\
<div class='col-lg-3 col-md-3 col-sm-3 col-xs-3 custom-paaddingnone text-center'>\
</div>\
<div class='col-lg-9 col-md-9 col-sm-9 col-xs-9 custom-paaddingnone'>\
<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12 custom-paaddingnone'>\
<div class='col-lg-10 col-md-10 col-sm-10 col-xs-10 custom-paaddingnone'>\
<select class='form-control' id ='memberid"+ rowNumber + subrowNumber + "'></select>\
</div>\
</div>\
</div>\
</div>";
addNewItemDetailHtml += "<div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 custom-paaddingnone'>\
<span class='glyphicon glyphicon-trash removeBtn' onclick = 'removeMemberDetail(this)'></span >\
</div>";
addNewItemDetailHtml += "</div>";
addNewItemDetailHtml += "</div>";
$("#itemmapWrapper" + rowNumber + "").attr("data-subrowNumber", subrowNumber);
$(".memberContainer").append(addNewItemDetailHtml);
intialize_memberDropDown(rowNumber, subrowNumber);
}
This code will take data from db to the member select menu.
function intialize_memberDropDown(rowNumber, subrowNumber) {
$.ajax({
type: "GET",
url: "/Member/GetAllMember/",
cache: false,
success: function (data) {
debugger
var countryHTMLString = "<option value ='0'>Select Member</option>";
if (data.isSucess) {
$.each(data.data, function (index, item) {
countryHTMLString += "<option value ='" + item.memberid + "'>" + item.membername + "</option>";
});
}
$("#memberid" + rowNumber + subrowNumber + "").html(countryHTMLString)
calculateTotalHotailBill(rowNumber)
}, error: function (err) {
debugger
}
});
}
This final code will remove member one I click the trash button I implemented on the append member function.
function removeMemberDetail(buttonElement) {
debugger
$(buttonElement).parents(".itemmapAllocationWrapper").remove();
if ($(".itemmapAllocationWrapper").html() == "") {
$("#memberid").removeAttr("disabled");
}
}