Код: Выделить всё
Client Code
Name
Bal
Due
Received
G S
Adj Y/N
All
GS Adj Amt
Bal
Due
Received SS
Adj Y/N
All
SS Adj Amt
Bal
Deposit
Withdraw
Rcvd
Prst
< /code>
JavaScript для загрузки строк таблицы: < /p>
$(document).ready(function(){
var savAcList = []; // to store ac infos
$.ajax({
type: 'GET',
url: '@Url.Action("GetSavingCollSheet", "CollectionSheetTranscation")',
dataType: 'json',
data: { adDate: $('#adDate').val(), centerCode: $('#centerCode').val(), collnSheetNo: $('#collnSheetNo').val() },
success: function (data) {
$.each(data, function (i, dets) {
var $row = $('' +
'' + dets.clientNo + '' +
'' + dets.clientName + '' +
'' + dets.MSBal + '' +
'' + dets.MSDue + '' +
'' +
'' + msadjCheckBox + '' +
'' + msadjCode + '' +
'' + msadjAmount + '' +
'' + dets.PSBal + '' +
'' + dets.PSRec + '' +
'' +
'' + psadjCheckBox + '' +
'' + psadjCode + '' +
'' + psadjAmount + '' +
'' + dets.OSBal + '' +
'' + dets.OSDep + '' +
'' + dets.OSWithdraw + '' +
'' + recFlag + '' +
'' + prFlag + ''
);
$('#tblSavingColl > tbody').append($row);
savAcList.push(dets.SavAcCode);
totMSDue += Number(dets.MSRec);
totPSDue += Number(dets.PSRec);
totOSDep += Number(dets.OSDep);
totOSWith += Number(dets.OSWithdraw);
totUFDue += Number(dets.UFRec);
psTransfer += Number(dets.PSAdjAmt);
msTransfer += Number(dets.MSAdjAmt);
if (dets.PresentFlag == "Y")
totPresent++;
});
var totalCollectionAmt = (totPSDue + totMSDue + totOSDep + totUFDue + 0 - (totOSWith + psTransfer + msTransfer));
$('#txttotalpensav').val(totPSDue);
$('#txttotaloptsav').val(totOSDep);
$('#txttotalwithdraw').val(totOSWith);
$('#txtpresent').val(totPresent);
$('#txttotalmonthsav').val(totMSDue);
$('#txttotunitfund').val(totUFDue);
$('#txttotalcolln').val(totalCollectionAmt);
$('#txtwelfarefundamt').val("0");
$('#txttotpentrans').val(psTransfer);
$('#txttotmontrans').val(msTransfer);
$('#txttotaltransfer').val(Number(psTransfer) + Number(msTransfer));
//alert(savAcList[0]);
},
error: function () {
alert("Error");
}
})
});
< /code>
Вопрос 1 < /strong>
Теперь после загрузки таблицы у нас есть флажок в 6 -м столбце и 12 -й столбец. Мне нужно было обработать событие флажона к < /p>
Когда проверяется флажок в 6 -м столбце, я должен загрузить значение в раскрывающемся в 7 -м столбце и значение 5 -го столбца на 8 -й столбец. Столбец. То, что я сделал, показано ниже, но приведенный ниже JavaScript делает немного ошибочных шагов, как мне нужно проверить первый флажок, который находится в 6-м столбце, а затем только на 12-м флажке столбца. И я при рассеянном флажке, если флажок 12 -й столбец не проверен, он очищает значение для 6 -го столбца и наоборот. var meroIndex = 0; var meroRow = 999;
$('#tblSavingColl').on('click', 'tr', function (e) {
//var myIndex = $('#tblSavingColl tr input[type="checkbox"]:checked').parent().index(); // get the index of the checkbox i.e. colIndex
var myIndex = $('#tblSavingColl tr input[type="checkbox"]').parent().index(); // get the index of the checkbox i.e. colIndex
var myRow = $(this).index(); // get the rowIndex
if (meroIndex == myIndex && myRow == meroRow)
myIndex = 12;
if (meroIndex == myIndex && myRow != meroRow)
myIndex = myIndex;
//alert("My Index " + myIndex + " MeroIndex = " + meroIndex);
meroIndex = myIndex;
meroRow = myRow;
var myTIndex = myIndex + 2;
var mySelIndex = myIndex + 1;
var ReceivedGS = $(this).find('td:nth-child(' + (Number(myIndex) - 1) + ') input').val();
var myAcCode = savAcList[Number(myRow)];
if ($(e.target).is('input[type=checkbox]')) {
var option = document.createElement("option"); // create a new element option [this here is created for a new option to be appended in the dropdownlist]
option.value = myAcCode; // associate the option element with value attribute
option.text = myAcCode; // associate the option element with text attribute
if ($(e.target).is(':checked')) // if the checkbox is checked
{
$(this).find('td:nth-child(' + myTIndex + ') input').val(ReceivedGS); // sets the textbox to the value in "ReceivedGS" variable
$(this).find('td:nth-child(' + mySelIndex + ') select').removeAttr("disabled"); // removes the disabled property of the dropdownlist
$(this).find('td:nth-child(' + mySelIndex + ') select').append(option); // append the option variable to the dropdownlist
$(this).find('td:nth-child(' + mySelIndex + ') select>option:eq(1)').attr('selected', true); // selects the newly created option of the dropdownlist
}
else // if the checkbox is not checked
{
$(this).find('td:nth-child(' + myTIndex + ') input').val("0"); // sets the textbox value to 0
$(this).find('td:nth-child(' + mySelIndex + ') select').find("option[value='" + myAcCode + "']").remove(); // removes the appended item from dropdownlist
$(this).find('td:nth-child(' + mySelIndex + ') select').prop("disabled", "disabled"); // applies the disabled property to the dropdownlist
}
}
});
< /code>
Мне нужна помощь для вышеуказанного. < /p>
И когда я хочу сохранить данные таблицы. Я хранил все ряды и столбцы в массиве и хотел передать контроллеру. Это все, что я сделал: < /p>
$('#btnSaveSaving').click(function () {
var myTableArray = [];
$('#tblSavingColl tbody tr').each(function () {
var arrayOfThisRow = [];
var tableData = $(this).find('td');
if (tableData.length > 0) {
tableData.each(function () {
if ($(this).find("input[type=text]").length) {
var myText = $(this).find("input[type=text]").val();
arrayOfThisRow.push(myText);
}
else if ($(this).find("input[type=checkbox]").length) {
var myText = $(this).find("input[type=checkbox]");
if ((myText).prop('checked') == true)
arrayOfThisRow.push('Y');
else arrayOfThisRow.push('N');
}
else if ($(this).find("select").length) {
var myText = $(this).find("select :selected").text();
arrayOfThisRow.push(myText);
}
else arrayOfThisRow.push($(this).text());
});
myTableArray.push(arrayOfThisRow);
}
});
var params = [];
/*for (var i = 0; i < myTableArray.length; i++) {
var dataValue = myTableArray[i].split(',');
params = {
collSheetNo: $('#collnSheetNo').val(),
clientNo: dataValue[0],
clientCode: dataValue[0],
clientName: dataValue[1],
UFAcNo: dataValue[6],
UFBal: dataValue[2],
UFDue: dataValue[3],
UFRec: dataValue[4],
MSAcNo: dataValue[6],
MSBal: "a",
MSDue: "a",
MSRec: "a",
MSAdjFlag: "a",
MSAdjACNo: "a",
MSAdjCode: "a",
MSAdjAmt: "a",
PSAcNo: "a",
PSBal: "a",
PSDue: "a",
PSRec: "a",
PSAdjFlag: "a",
PSAdjAcNo: "a",
PSAdjCode: "a",
PSAdjAmt: "a",
OSAcNo: "a",
OSBal: "a",
OSDep: "a",
OSWithdraw: "a",
ReceivedFlag: "a",
PresentFlag: "a"
};
}*/
$.ajax({
type: 'POST',
url: '@Url.Action("SaveSavingColln", "CollectionSheetTranscation")',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ savingColln: params}),
success: function (result) {
alert(result);
},
error: function () {
alert("Error while saving Saving Collection Sheet");
}
});
});
< /code>
Комментированные строки заполняют переменную Params. Но на самом деле он не выполняется после < /p>
var dataValue = myTableArray[i].split(',');
< /code>
Вопрос 2 < /strong>
Итак, у меня возникает проблема при отправке данных и контроллеру.
Ну, я даже попробовал следующий способ передать данные контроллеру. data: JSON.stringify({ savingColln: myTableArray}),
< /code>
Я помещаю точку останова на контроллере, чтобы узнать, поступают ли данные в контроллер или нет. На самом деле он достигает контроллера и длины MyTableArray, но никакого значения не получает. Мой контроллер заключается в следующем: < /p>
public JsonResult SaveSavingColln(List savingColln)
{
string result = iCollService.SavingCollnSave(savingColln);
return Json(result, JsonRequestBehavior.AllowGet);
}
Подробнее здесь: https://stackoverflow.com/questions/416 ... -mvc-razor