Skip to content

Commit

Permalink
maint: Upgrade to Patternslib v4 final - sortable table customizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Apr 20, 2021
1 parent b7879f7 commit 084fefb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bundle-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import registry from "patternslib/src/core/registry.js";
import registry from "@patternslib/patternslib/src/core/registry.js";
import "./src/pat-sortable-table.js";

registry.init();
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "pat-PATTERN_TEMPLATE",
"name": "pat-sortable-table",
"version": "1.0.0",
"description": "A pattern for PATTERN_TEMPLATE",
"description": "A pattern for interactive tables.",
"license": "MIT",
"main": "./src/PATTERN_TEMPLATE.js",
"main": "./src/pat-sortable-table.js",
"dependencies": {
"datatables.net-dt": "^1.10.22",
"@patternslib/patternslib": "4"
},
"devDependencies": {
Expand Down Expand Up @@ -69,9 +70,9 @@
"name": "Syslab GesmbH",
"email": "dev@syslab.com"
},
"homepage": "https://gitub.com/patternslib/pat-PATTERN_TEMPLATE",
"homepage": "https://github.com/patternslib/pat-sortable-table",
"repository": {
"type": "git",
"url": "https://gitub.com/patternslib/pat-PATTERN_TEMPLATE.git"
"url": "https://github.com/patternslib/pat-sortable-table.git"
}
}
18 changes: 6 additions & 12 deletions src/pat-sortable-table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import $ from "jquery";
import "regenerator-runtime/runtime"; // needed for ``await`` support
import Base from "patternslib/src/core/base";
import Parser from "patternslib/src/core/parser";
import Base from "@patternslib/patternslib/src/core/base";
import Parser from "@patternslib/patternslib/src/core/parser";

const parser = new Parser("sortable-table");
parser.addArgument("paging-type", "numbers", [
Expand All @@ -26,22 +25,17 @@ export default Base.extend({
name: "sortable-table",
trigger: ".pat-sortable-table",

async init(el, opts) {
if (el.jquery) {
el = el[0];
}
this.el = el;
this.options = parser.parse(el, opts);
async init() {
this.options = parser.parse(this.$el, this.options);
await import("datatables.net");

let pageLengthMenu = this.options.page["length-menu"];
if (typeof pageLengthMenu === "string") {
pageLengthMenu = JSON.parse(pageLengthMenu);
}

$(el).DataTable({
dom:
'<"data-table-top"if>rt<"data-table-bottom"lp><"data-table-clear">',
this.$el.DataTable({
dom: '<"data-table-top"if>rt<"data-table-bottom"lp><"data-table-clear">',
retrieve: true,
pagingType: this.options.pagingType,
pageLength: this.options.page.length,
Expand Down
14 changes: 4 additions & 10 deletions src/pat-sortable-table.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "regenerator-runtime/runtime"; // needed for ``await`` support
import pattern from "./pat-sortable-table";
import utils from "patternslib/src/core/utils";
import utils from "@patternslib/patternslib/src/core/utils";

describe("pat-sortable-table", () => {
beforeEach(() => {
Expand All @@ -10,9 +10,7 @@ describe("pat-sortable-table", () => {
it("is initialized correctly and allows sorting", async (done) => {
document.body.innerHTML = small_table;

const instance = pattern.init(
document.querySelector(".pat-sortable-table")
);
pattern.init(document.querySelector(".pat-sortable-table"));
await utils.timeout(1);

let td;
Expand Down Expand Up @@ -62,9 +60,7 @@ describe("pat-sortable-table", () => {
language-search-placeholder: type term;`
);

const instance = pattern.init(
document.querySelector(".pat-sortable-table")
);
pattern.init(document.querySelector(".pat-sortable-table"));
await utils.timeout(1);

expect(document.querySelectorAll("tbody").length).toBe(1);
Expand All @@ -76,9 +72,7 @@ describe("pat-sortable-table", () => {
.querySelector(".dataTables_length")
.textContent.indexOf("per page") > -1
).toBeTruthy();
expect(document.querySelector(".dataTables_filter").textContent).toBe(
"find"
);
expect(document.querySelector(".dataTables_filter").textContent).toBe("find");
expect(
document
.querySelector(".dataTables_filter input[type=search]")
Expand Down

0 comments on commit 084fefb

Please sign in to comment.