if you check your source by console, you will see your selectors won't work as expected. And if your colorization is working, maybe your clicks on the data table will fail (e. g. and maybe sorting).
Put all your TRs into one table.
Mark each TR with a data-attribute (data-*) and put your value into it (here: oRacuni.Storno).
Set an event listener to each TR inside of this table and handle data-* inside your function (modal box or alert).
Maybe something like this ...
$('#TablicaRacuni tbody').append("<tr data-storno=""+oRacuni.Storno+""><td>" + oRacuni.Kolicina + "</td><td>" + VrstaGor + "</td><td>" + oRacuni.DatumVrijeme + "</td><td>" + oRacuni.Zaposlenik + "</td><td>" + oRacuni.Cijena + "</td></tr>" );
Please, think about appending a full string with all entries at once to your DOM - not one by one (performance!)!
$(function(){
$('#TablicaRacuni tbody tr').on('click', function () {
let dataAttr = parseInt($(this).data('storno'), 10); // 1 or 0
switch (dataAttr) {
case 1:
alert("Ovaj ra?un je ve? storniran.");
break;
default: // 0 and everything else
data = table.row(this).data(); // not sure, what you expect here?!
$('#Storno').modal("show");
break;
}
});
});
I haven't tested this, but this could be solid to your needs.
Last but not least and if you are not happy with the solution above: if you want to remove unwanted event listeners, you can use unbind('click') on a group of selectors.
You will need further steps (change data-storno if storno is used in modalbox), so setting an identifier at each TR (e. g. class="vehicle[ID]"; [TR] is a unique ID out of your database) would speed up your further work, too, to adress such interactions directly to your overview (instead of reloading; e. g. deleting, updating, set to un-storno).
At least, please ...
- ... re-think use of global vars in days of ECMA6, let and so on.
- ... two document.ready() inside your function PopuniTablicuRacuni()
best regards, stay healthy and have fun with coding!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…