Hi,
Need to implement one logic could you please help me as soon as possible it’s urgent
How do i achieve this below logic in JavaScript If i click on Add button this below logic should happen First time if i add the subject priority and school level priority will be 1 later on it should compare and execute each every row before adding to the table
The issue is
a) If the subject remains same and school level changes subject priority remains same and school level priority should increment
b) If the subject changes subject priority also changes it will increment and school level priority remains basically
a) For same subject school level priority changes means subject priority same and school level priority will get increment
b) if subject changes school level priority remains and subject priority will get increment
<div class="row ">
<div class="col-sm-12 text-right">
<button type="button"
id="updateButton"
class="btn btn-success"
onclick="TutorCourseUpdate();">
Add
</button>
<button type="button"
id="ResetButton"
class="btn btn-danger"style="color: #ffffff; background-color: #f4ad49; border-color: #f4ad49;"
onclick="TutorCourseReset();">
Reset
</button>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<table id="tbl_TutorcoursList" style="table-layout:fixed;word-wrap:break-word" class="table table-hover table-bordered table-striped table-responsive">
<thead>
<tr>
<th>Subject</th>
<th hidden>SubjectId</th>
<th>School level</th>
<th hidden>School levelId</th>
<th>Course</th>
<th hidden>CourseId</th>
<th>Subject Priority</th>
<th>School level Priority</th>
<th>Action</th>
@*<th>Edit </th>
<th>Delete</th>*@
</tr>
</thead>
<tbody id="tblBody_TutorcoursList"></tbody>
</table>
</div>
</div>
function TutorCourseAddToTable() {
var values = [];
var valueschl = [];
$('#tbl_TutorcoursList tbody tr').each(function () {
var $tblrow = $(this);
var value = $tblrow.find("[name=subjctpriorty]").text();
if (!isNaN(value))
values.push(value);
var valuesch = $tblrow.find("[name=subjctpriorty]").text();
if (!isNaN(valuesch))
valueschl.push(valuesch);
});
if (values.length > 0) {
maxValue = Math.max.apply(null, values);
maxValue++;
}
else {
maxValue = 1;
}
if (valueschl.length > 0) {
maxValueschl = Math.max.apply(null, valueschl);
maxValueschl++;
}
else {
maxValueschl = 1;
}
let tab = $('#tblBody_TutorcoursList');
// Append TutorCourse to table
tab.append(TutorCourseTableRow(_nextId));
// Increment next ID to use
_nextId += 1;
}
function TutorCourseTableRow(id) {
debugger;
var Subject = $('#ddlSubject option:selected').text().trim();
var SubjectId = $('#ddlSubject').val().trim();
var SchoolLevel = $('#ddlSchoollevel option:selected').text().trim();
var SchoolLevelId = $('#ddlSchoollevel').val().trim();
var selectedCourses = '';
var selectedCourseIDs = '';
$.each($('#ddlSelectedCourse option'), function (key, value) {
selectedCourseIDs += $(this).val() + ',';
});
$.each($('#ddlSelectedCourse option'), function (key, value) {
selectedCourses += $(this).text() + ',';
});
selectedCourseIDs = selectedCourseIDs.replace(/,\s*$/, "");
selectedCourses = selectedCourses.replace(/,\s*$/, "");
var ret = '<tr><td name="sub">' + Subject + '</td><td hidden name="subId">' + SubjectId + '</td><td name="sclevl">' + SchoolLevel + '</td><td hidden name="sclevlId">' + SchoolLevelId + '</td><td name="selectdcours">' + selectedCourses + '</td><td hidden name="selectdcoursId">' + selectedCourseIDs + '</td><td name="subjctpriorty">' + maxValue + '</td><td name="schllvlpriorty">' + maxValueschl + '</td><td><i title="Click on this button to edit the details" class="fa fa-pencil btnedit fev-cursor" aria-hidden="true" onclick= "TutorCourseEdit(this)"; data-id=' + id + '></i><i title="Click on this button to delete the details" class="fa fa-trash btndelete color-red fev-cursor ml10" aria-hidden="true" onclick= "TutorCourseDelete(this)";" data-id=' + id + '></i></td></td></tr>'
return ret;
}