@fluid-topics/ft-filterable-table 1.1.63 → 1.1.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,7 @@ export declare class FtFilterableTable<T extends Record<string, any>> extends Ft
21
21
  protected update(props: PropertyValues): void;
22
22
  private updateFilterOptions;
23
23
  private renderHeader;
24
+ private getOppositeSortOrder;
24
25
  private renderColumnSort;
25
26
  private dispatchChangeEvent;
26
27
  private renderColumnFilter;
@@ -127,15 +127,19 @@ class FtFilterableTable extends FtLitElement {
127
127
  </div>
128
128
  `;
129
129
  }
130
+ getOppositeSortOrder(sortOrder) {
131
+ return sortOrder === "asc" ? "desc" : "asc";
132
+ }
130
133
  renderColumnSort(column, index) {
131
134
  var _a;
132
135
  const isSorted = this.currentSort && this.currentSort.column === index;
133
136
  const sortIcon = isSorted ? (this.currentSort.order === "asc" ? "expand_less" : "expand_more") : "unfold_more";
134
137
  const sort = () => {
135
- var _a;
138
+ var _a, _b;
139
+ const defaultSort = (_a = column.defaultSortOrder) !== null && _a !== void 0 ? _a : "asc";
136
140
  this.currentSort = {
137
141
  column: index,
138
- order: isSorted && ((_a = this.currentSort) === null || _a === void 0 ? void 0 : _a.order) === "asc" ? "desc" : "asc"
142
+ order: isSorted && ((_b = this.currentSort) === null || _b === void 0 ? void 0 : _b.order) === defaultSort ? this.getOppositeSortOrder(defaultSort) : defaultSort
139
143
  };
140
144
  this.dispatchChangeEvent();
141
145
  };
@@ -1507,14 +1507,14 @@ const Be={fontSize:o.FtCssVariableFactory.create("--ft-text-field-font-size","",
1507
1507
  </div>
1508
1508
  ${this.renderColumnFilter(t,o)}
1509
1509
  </div>
1510
- `}renderColumnSort(t,o){var i;const r=this.currentSort&&this.currentSort.column===o,n=r?"asc"===this.currentSort.order?"expand_less":"expand_more":"unfold_more";return null===(i=t.sortable)||void 0===i||i?e.html`
1510
+ `}getOppositeSortOrder(t){return"asc"===t?"desc":"asc"}renderColumnSort(t,o){var i;const r=this.currentSort&&this.currentSort.column===o,n=r?"asc"===this.currentSort.order?"expand_less":"expand_more":"unfold_more";return null===(i=t.sortable)||void 0===i||i?e.html`
1511
1511
  <ft-button
1512
1512
  round
1513
1513
  dense
1514
1514
  iconVariant="material"
1515
1515
  icon="${n}"
1516
1516
  label="Sort ${t.title}"
1517
- @click=${()=>{var t;this.currentSort={column:o,order:r&&"asc"===(null===(t=this.currentSort)||void 0===t?void 0:t.order)?"desc":"asc"},this.dispatchChangeEvent()}}
1517
+ @click=${()=>{var e,i;const n=null!==(e=t.defaultSortOrder)&&void 0!==e?e:"asc";this.currentSort={column:o,order:r&&(null===(i=this.currentSort)||void 0===i?void 0:i.order)===n?this.getOppositeSortOrder(n):n},this.dispatchChangeEvent()}}
1518
1518
  part="${this.columnPart("sort-button",o)}"
1519
1519
  ></ft-button>
1520
1520
  `:e.nothing}dispatchChangeEvent(){this.dispatchEvent(new Ni({filters:this.filters.map(((t,o)=>({column:o,value:t.value}))).filter((t=>null!=t.value)),sort:this.currentSort}))}renderColumnFilter(t,o){var i,n,a;const l=t=>{this.filters[o]={value:t.detail},this.requestUpdate(),this.dispatchChangeEvent()},s=null!==(i=this.filterOptions[o])&&void 0!==i?i:[];switch(null!==(n=t.filter)&&void 0!==n?n:"text"){case"text":return e.html`
@@ -1675,14 +1675,14 @@ const Ys={fontSize:xo.create("--ft-text-field-font-size","","SIZE","14px"),label
1675
1675
  </div>
1676
1676
  ${this.renderColumnFilter(t,e)}
1677
1677
  </div>
1678
- `}renderColumnSort(t,e){var o;const r=this.currentSort&&this.currentSort.column===e,i=r?"asc"===this.currentSort.order?"expand_less":"expand_more":"unfold_more";return null===(o=t.sortable)||void 0===o||o?Jt`
1678
+ `}getOppositeSortOrder(t){return"asc"===t?"desc":"asc"}renderColumnSort(t,e){var o;const r=this.currentSort&&this.currentSort.column===e,i=r?"asc"===this.currentSort.order?"expand_less":"expand_more":"unfold_more";return null===(o=t.sortable)||void 0===o||o?Jt`
1679
1679
  <ft-button
1680
1680
  round
1681
1681
  dense
1682
1682
  iconVariant="material"
1683
1683
  icon="${i}"
1684
1684
  label="Sort ${t.title}"
1685
- @click=${()=>{var t;this.currentSort={column:e,order:r&&"asc"===(null===(t=this.currentSort)||void 0===t?void 0:t.order)?"desc":"asc"},this.dispatchChangeEvent()}}
1685
+ @click=${()=>{var o,i;const n=null!==(o=t.defaultSortOrder)&&void 0!==o?o:"asc";this.currentSort={column:e,order:r&&(null===(i=this.currentSort)||void 0===i?void 0:i.order)===n?this.getOppositeSortOrder(n):n},this.dispatchChangeEvent()}}
1686
1686
  part="${this.columnPart("sort-button",e)}"
1687
1687
  ></ft-button>
1688
1688
  `:te}dispatchChangeEvent(){this.dispatchEvent(new Wc({filters:this.filters.map(((t,e)=>({column:e,value:t.value}))).filter((t=>null!=t.value)),sort:this.currentSort}))}renderColumnFilter(t,e){var o,r,i;const n=t=>{this.filters[e]={value:t.detail},this.requestUpdate(),this.dispatchChangeEvent()},a=null!==(o=this.filterOptions[e])&&void 0!==o?o:[];switch(null!==(r=t.filter)&&void 0!==r?r:"text"){case"text":return Jt`
@@ -5,6 +5,7 @@ export interface ColumnConfiguration<T> {
5
5
  getter: string | Getter<T>;
6
6
  render?: (value: any, index: number) => string | TemplateResult;
7
7
  sortable?: boolean;
8
+ defaultSortOrder?: "asc" | "desc";
8
9
  comparator?: (a: any, b: any) => number;
9
10
  filter?: "text" | "select" | "none";
10
11
  stringify?: (value: any, index: number) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-filterable-table",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "A dynamic table with filters",
5
5
  "keywords": [
6
6
  "Lit"
@@ -22,11 +22,11 @@
22
22
  "test": "echo \"Error: run tests from root\" && exit 1"
23
23
  },
24
24
  "dependencies": {
25
- "@fluid-topics/ft-button": "1.1.63",
26
- "@fluid-topics/ft-select": "1.1.63",
27
- "@fluid-topics/ft-text-field": "1.1.63",
28
- "@fluid-topics/ft-wc-utils": "1.1.63",
25
+ "@fluid-topics/ft-button": "1.1.65",
26
+ "@fluid-topics/ft-select": "1.1.65",
27
+ "@fluid-topics/ft-text-field": "1.1.65",
28
+ "@fluid-topics/ft-wc-utils": "1.1.65",
29
29
  "lit": "3.1.0"
30
30
  },
31
- "gitHead": "6f2845e11b1b3a26814c32cacd5413802aa28157"
31
+ "gitHead": "513933b7426b594cb72b427d60821ffc891f8584"
32
32
  }