This commit is contained in:
parent
00a4c749f0
commit
2589cabec6
@ -55,6 +55,8 @@
|
|||||||
"@prisma/client": "^6.6.0",
|
"@prisma/client": "^6.6.0",
|
||||||
"@tailwindcss/forms": "^0.5.10",
|
"@tailwindcss/forms": "^0.5.10",
|
||||||
"datatables.net-dt": "^2.2.2",
|
"datatables.net-dt": "^2.2.2",
|
||||||
|
"datatables.net-select": "^3.0.0",
|
||||||
|
"datatables.net-select-dt": "^3.0.0",
|
||||||
"discord.js": "^14.18.0",
|
"discord.js": "^14.18.0",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"ejs": "^3.1.10",
|
"ejs": "^3.1.10",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
// import DataTable from "datatables.net";
|
import "datatables.net-select-dt";
|
||||||
import DataTable from "datatables.net-dt"
|
import DataTable, { Api } from "datatables.net-dt"
|
||||||
import HSDropdown from "@preline/dropdown";
|
import HSDropdown from "@preline/dropdown";
|
||||||
import HSOverlay, { IOverlayOptions } from "@preline/overlay";
|
import HSOverlay, { IOverlayOptions } from "@preline/overlay";
|
||||||
import HSSelect, { ISelectOptions } from "@preline/select";
|
import HSSelect, { ISelectOptions } from "@preline/select";
|
||||||
@ -217,11 +217,10 @@ const ajaxSettings: AjaxSettings = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const tableOptions: any = {
|
const tableOptions: IDataTableOptions = {
|
||||||
ajax: ajaxSettings,
|
ajax: ajaxSettings,
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
processing: true,
|
processing: true,
|
||||||
selecting: true,
|
|
||||||
select: {
|
select: {
|
||||||
style: "multi",
|
style: "multi",
|
||||||
selector: "td:first-child input[type='checkbox']"
|
selector: "td:first-child input[type='checkbox']"
|
||||||
@ -246,11 +245,7 @@ const table: HSDataTable = new HSDataTable(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onTableSelectChange = () => {
|
const onTableSelectChange = () => {
|
||||||
console.log("table select change")
|
|
||||||
const rows = (table as any).dataTable.rows();
|
|
||||||
debugger;
|
|
||||||
const selectedRowsCount = (table as any).dataTable.rows({ selected: true }).count();
|
const selectedRowsCount = (table as any).dataTable.rows({ selected: true }).count();
|
||||||
// const selectedRowsCount = $("#table tbody input[data-hs-datatable-row-selecting-individual]:checked").length;
|
|
||||||
$("#deleteRowsBtn").prop("disabled", selectedRowsCount === 0);
|
$("#deleteRowsBtn").prop("disabled", selectedRowsCount === 0);
|
||||||
$(".rows-selected-count-js").text(selectedRowsCount);
|
$(".rows-selected-count-js").text(selectedRowsCount);
|
||||||
|
|
||||||
@ -264,16 +259,29 @@ const onTableSelectChange = () => {
|
|||||||
.on("draw", onTableSelectChange);
|
.on("draw", onTableSelectChange);
|
||||||
|
|
||||||
$("#selectAllBox").on("change", function() {
|
$("#selectAllBox").on("change", function() {
|
||||||
debugger;
|
|
||||||
// TODO: debug why the select and deselect methods don't exist
|
|
||||||
(this as HTMLInputElement).checked
|
(this as HTMLInputElement).checked
|
||||||
? (table as any).dataTable.rows().select()
|
? (table as any).dataTable.rows().select()
|
||||||
: (table as any).dataTable.rows().deselect();
|
: (table as any).dataTable.rows().deselect();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#deleteRowsBtn").on("click", () => {
|
$("#deleteRowsBtn").on("click", async () => {
|
||||||
const rowIds = (table as any).dataTable.rows({ selected: true }).data().toArray().map((row: any) => row.id);
|
const dt: Api = (table as any).dataTable;
|
||||||
alert(JSON.stringify(rowIds, null, 4));
|
const rowsData = dt.rows({ selected: true }).data().toArray();
|
||||||
|
const rowIds = rowsData.map((row: prisma.Feed) => row.id);
|
||||||
|
|
||||||
|
await $.ajax({
|
||||||
|
url: `/guild/${guildId}/feeds/api`,
|
||||||
|
method: "delete",
|
||||||
|
dataType: "json",
|
||||||
|
data: { ids: rowIds },
|
||||||
|
success: () => {
|
||||||
|
dt.draw();
|
||||||
|
dt.rows().deselect();
|
||||||
|
},
|
||||||
|
error: error => {
|
||||||
|
alert(typeof error === "object" ? JSON.stringify(error, null, 4) : error);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user