Remove select checkboxes when actions unavailable
This commit is contained in:
1 parent
795a0f8273
commit
b51c97e97a
1 file changed
+19
-12
+19
-12
@@ -40,6 +40,19 @@ function renderTable(
|
|||||||
recordActionsCallback?: Children | ((record: Record<string, any>) => Children)
|
recordActionsCallback?: Children | ((record: Record<string, any>) => Children)
|
||||||
): Children {
|
): Children {
|
||||||
const records = data || [];
|
const records = data || [];
|
||||||
|
|
||||||
|
// Actions bar
|
||||||
|
let buttons: Children = [];
|
||||||
|
if (typeof actionsCallback === "function") {
|
||||||
|
buttons = actionsCallback(selected);
|
||||||
|
if (!Array.isArray(buttons)) buttons = [buttons];
|
||||||
|
} else if (Array.isArray(actionsCallback)) {
|
||||||
|
buttons = actionsCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Table header
|
||||||
|
const labels = [];
|
||||||
|
if (buttons.length) {
|
||||||
const selectAll = m("input", {
|
const selectAll = m("input", {
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: records.length && selected.size === records.length,
|
checked: records.length && selected.size === records.length,
|
||||||
@@ -52,9 +65,9 @@ function renderTable(
|
|||||||
},
|
},
|
||||||
disabled: !total
|
disabled: !total
|
||||||
});
|
});
|
||||||
|
labels.push(m("th", selectAll));
|
||||||
|
}
|
||||||
|
|
||||||
// Table header
|
|
||||||
const labels = [m("th", selectAll)];
|
|
||||||
for (let i = 0; i < attributes.length; i++) {
|
for (let i = 0; i < attributes.length; i++) {
|
||||||
const attr = attributes[i];
|
const attr = attributes[i];
|
||||||
const label = attr.label;
|
const label = attr.label;
|
||||||
@@ -87,6 +100,8 @@ function renderTable(
|
|||||||
const rows = [];
|
const rows = [];
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const id = record["_id"] || record["DeviceID.ID"].value[0];
|
const id = record["_id"] || record["DeviceID.ID"].value[0];
|
||||||
|
const tds = [];
|
||||||
|
if (buttons.length) {
|
||||||
const checkbox = m("input", {
|
const checkbox = m("input", {
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: selected.has(id),
|
checked: selected.has(id),
|
||||||
@@ -99,8 +114,9 @@ function renderTable(
|
|||||||
e.redraw = false;
|
e.redraw = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
tds.push(m("td", checkbox));
|
||||||
|
}
|
||||||
|
|
||||||
const tds = [m("td", checkbox)];
|
|
||||||
for (const attr of attributes) {
|
for (const attr of attributes) {
|
||||||
const attrs = {};
|
const attrs = {};
|
||||||
let valueComponent;
|
let valueComponent;
|
||||||
@@ -180,15 +196,6 @@ function renderTable(
|
|||||||
m("tr", m("td", { colspan: labels.length }, footerElements))
|
m("tr", m("td", { colspan: labels.length }, footerElements))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Actions bar
|
|
||||||
let buttons: Children = [];
|
|
||||||
if (typeof actionsCallback === "function") {
|
|
||||||
buttons = actionsCallback(selected);
|
|
||||||
if (!Array.isArray(buttons)) buttons = [buttons];
|
|
||||||
} else if (Array.isArray(actionsCallback)) {
|
|
||||||
buttons = actionsCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
const children = [
|
const children = [
|
||||||
m(
|
m(
|
||||||
"table.table.highlight",
|
"table.table.highlight",
|
||||||
|
|||||||
Reference in new issue
Block a user