I would like to create one table that has "memory" of certain variable.
Currently I've made appending two tables, one of them has #table_body_storno:
- when
oRacuni.Storno = 1, color this one red and make it unusable again as the receive is already been cancelled
Other one is #table_body:
- when
oRacuni.Storno = 0, make it clickable and call function$('#Storno').modal("show");
I've tried multiple ways, adding .addClass when appending table row, adding tr style only etc Problem is if I use this code (down) I get two tables, upper one which is "normal" and bottom one which is "red" and not usable. I would like to merge these two into same table, so listed receives are ordered by some order, and not by upper ones - normal, down - cancelled.
var data;
function PopuniTablicuRacuni() {
var table;
aRacuni.forEach(function (oRacuni) {
var VrstaGor = "";
if (oRacuni.VrstaGoriva == 1) {
VrstaGor = "Diesel";
} else if (oRacuni.VrstaGoriva == 2) {
VrstaGor = "Benzin";
}
if (oRacuni.Storno == 1) {
$("#table_body_storno").append("<tr><td>" + oRacuni.Kolicina + "</td><td>" + VrstaGor + "</td><td>" + oRacuni.DatumVrijeme + "</td><td>" + oRacuni.Zaposlenik + "</td><td>" + oRacuni.Cijena + "</td></tr>" );
} else {
$("#table_body").append("<tr><td>" + oRacuni.Kolicina + "</td><td>" + VrstaGor + "</td><td>" + oRacuni.DatumVrijeme + "</td><td>" + oRacuni.Zaposlenik + "</td><td>" + oRacuni.Cijena + "</td></tr>");
}
$(document).ready(function () {
table = $('#TablicaRacuni').DataTable();
console.log(table);
});
});
$(document).ready(function () {
$('#TablicaRacuni tbody#table_body').on('click', 'tr', function () {
data = table.row(this).data();
$('#Storno').modal("show");
});
$('#TablicaRacuni tbody#table_body_storno').on('click', 'tr', function () {
alert("Ovaj račun je već storniran.")
});
});
}
Then when I was trying with .addClass it looks good, but I can not figure out how to make "red" ones un-clickable.
if (oRacuni.Storno == 1) {
$("#table_body").addClass("storno").append("<tr style='color: #ff0000;'><td>" + oRacuni.Kolicina + "</td><td>" + VrstaGor + "</td><td>" + oRacuni.DatumVrijeme + "</td><td>" + oRacuni.Zaposlenik + "</td><td>" + oRacuni.Cijena + "</td></tr>" );
} else {
$("#table_body").append("<tr><td>" + oRacuni.Kolicina + "</td><td>" + VrstaGor + "</td><td>" + oRacuni.DatumVrijeme + "</td><td>" + oRacuni.Zaposlenik + "</td><td>" + oRacuni.Cijena + "</td></tr>");
}
$(document).ready(function () {
$('#TablicaRacuni tbody#table_body').on('click', 'tr', function () {
data = table.row(this).data();
$('#Storno').modal("show");
});
$('#TablicaRacuni tbody#table_body.storno').on('click', 'tr', function () {
alert("Ovaj račun je već storniran.")
});
});

