blob: 8d54a846cdfa177b2c690a7bda04eef16bae2f7a (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/** Handlers for events in datatables **/
var dtAddRowSelectionHandler = (tableId) => {
$(tableId).on("draw.dt", (event) => {
$(".chk-row-select").on("change", (event) => {
var checkboxOrRadio = event.target;
var tablerow = checkboxOrRadio.parentElement.parentElement;
var tableclass = tablerow.getAttribute("class");
if(checkboxOrRadio.checked) {
if (checkboxOrRadio.type == "radio") {
$(tableId + " tr").each((index, row) => {
var rowKlass = $(row).attr("class") || "";
row.setAttribute(
"class", rowKlass.replaceAll("selected", "").trim());
});
}
tablerow.setAttribute("class", `${tableclass} selected`);
}
else {
tablerow.setAttribute(
"class", tableclass.replaceAll("selected", "").trim());
}
});
});
};
var toggleCheck = (checkboxOrRadio) => {
if (checkboxOrRadio.length > 0) {
var currentState = checkboxOrRadio.prop("checked");
var newState = !currentState;
if (currentState == true && checkboxOrRadio.attr("type").toLowerCase() == "radio") {
// We don't want to toggle from true to false by clicking on the row
// if it is a radio button.
newState = currentState;
}
checkboxOrRadio.prop("checked", newState);
checkboxOrRadio.trigger("change");
}
};
var dtAddRowClickHandler = (tableId) => {
$(tableId).on("draw.dt", (event) => {
$(tableId + " tbody tr").on("click", (event) => {
var row = event.target.closest("tr");
var checkboxOrRadio = $(row).find(".chk-row-select");
toggleCheck(checkboxOrRadio);
});
});
};
var dtAddCommonHandlers = (tableId) => {
dtAddRowSelectionHandler(tableId);
dtAddRowClickHandler(tableId);
}
|