`;
+ if (this.config.footer.detail) {
+ html += ``;
+ }
+
+ if (this.config.footer.pagination) {
+ html += ``;
+ }
+
+ html += `
`;
+ $(this.tableId).append(html);
+ this.attachPaginationEventListeners();
+ this.attachPerPageEventListeners();
+ }
+
+ // Render table
+ async render() {
+ let data;
+ let params = {
+ per_page: this.config.per_page,
+ page: this.config.page,
+ };
+ // Clear html
+ $(this.tableId).html("");
+ // Initial headers
+ $(this.tableId).append(this.renderHeads());
+ this.attachSortEventListeners(".ri-expand-up-down-fill");
+
+ // Append 'order' and 'filter' into params if exist
+ if (this.config.hasOwnProperty("ajax")) {
+ if (this.config.order !== null) {
+ Object.assign(params, this.config.order);
+ }
+ if (this.config.filter !== null) {
+ Object.assign(params, this.config.filter);
+ }
+ // Call ajax and render data
+ data = await this.config.ajax(params);
+ this.renderRows(data);
+ } else {
+ // Use data transmitted directly
+ data = this.config.data;
+ this.renderRows(data);
+ }
+
+ // Start listening to events of already initialized buttons
+ this.attachActionEventListeners(".btn_edit");
+ this.attachActionEventListeners(".btn_done");
+ }
+
+ // Get the current configuration of the table
+ getConfig() {
+ return this.config;
+ }
+
+ // Automatically merger new config and re-render
+ updateConfig(newConfig) {
+ this.config = {
+ ...this.config,
+ ...newConfig,
+ };
+ this.render();
+ }
+
+ // Define and automatically create edit buttons
+ // Used in rowRender configuration
+ actionEdit(row) {
+ return `
+
+
+
+
+ `;
+ }
+
+ // Define and automatically create editable cells
+ // Used in rowRender configuration
+ cellEdit(colName, colValue) {
+ return `
+
${colValue}
+
+ `;
+ }
+
+ // Works when the edit button is clicked
+ rowEdit(rowId) {
+ this.config.heads.map((col) => {
+ var cellShow = $(`#row_${rowId} .cell_show .${col.name}`);
+ var cellEdit = $(`#row_${rowId} .cell_edit .${col.name}`);
+
+ if (cellShow) {
+ cellShow.hide();
+ }
+
+ if (cellEdit) {
+ cellEdit.show();
+ }
+ });
+ $(`#row_${rowId} div .btn_done`).show();
+ $(`#row_${rowId} div .btn_edit`).hide();
+ }
+
+ rowEditDone(rowId) {
+ // Initial params with row id
+ let params = {
+ id: parseInt(rowId),
+ };
+
+ // Get api update info
+ let apiUpdateInfo = this.config.apiUpdate;
+
+ // Add edited values to params
+ this.config.heads.map((col) => {
+ var cellEdit = $(`#row_${rowId} .cell_edit .${col.name}`);
+
+ if (cellEdit.val()) {
+ Object.assign(params, {
+ [col.name]: cellEdit.val(),
+ });
+ }
+ });
+ // Call API update data row
+ if (this.config.hasOwnProperty("apiUpdate")) {
+ $.ajax({
+ url: apiUpdateInfo.url,
+ type: apiUpdateInfo.type,
+ data: params,
+ headers: apiUpdateInfo.headers,
+ success: (response) => {
+ // alert("Edit success");
+ this.render();
+ },
+ error: function (error) {
+ console.log(error);
+ alert("Edit Fail");
+ },
+ });
+ } else {
+ alert("Missing updated API information");
+ }
+
+ //
+ $(`#row_${rowId} div .btn_done`).hide();
+ $(`#row_${rowId} div .btn_edit`).show();
+ }
+
+ // Update config and render when change per page
+ changePerPage() {
+ this.config.per_page = $(`${this.tableId} #perPageSelect`).val();
+ this.render();
+ }
+}
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..c3c621a
--- /dev/null
+++ b/index.html
@@ -0,0 +1,183 @@
+
+
+
+
+ JDataTable
+
+
+
+
+
+
+
+
+
+
+
+
+
JDataTable
+
A library used to initialize a basic data table. Includes the main components of a data table such as: sorting, per page, pagination, table. Supports additional configuration of search and filtering features.
+
+
+
+
+
Filter
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.php b/index.php
deleted file mode 100644
index 7b1a868..0000000
--- a/index.php
+++ /dev/null
@@ -1,552 +0,0 @@
-
-
-
-
- Bootstrap Example
-
-
-
-
-
-
-
-
-
-
-
-
Striped Rows
-
The .table-striped class adds zebra-stripes to a table: