aio-table 14.0.1 → 14.0.2

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.
Files changed (3) hide show
  1. package/index.d.ts +7 -4
  2. package/index.js +22 -26
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -196,8 +196,11 @@ export type I_table_sort<T> = {
196
196
  active?: boolean;
197
197
  dir?: 'dec' | 'inc';
198
198
  title?: ReactNode;
199
- sortId: string;
200
- getValue?: (row: T) => any;
199
+ sortId?: string;
200
+ getValue?: (row: T, dir: 'inc' | 'dec') => any;
201
+ isDate?: boolean;
202
+ columnId?: string;
203
+ order?: number;
201
204
  };
202
205
  export declare const useSort: <T>(p: {
203
206
  fa?: boolean;
@@ -212,8 +215,8 @@ export declare const useSort: <T>(p: {
212
215
  getSortedRows: (rows: T[]) => T[];
213
216
  changeSort: (sortId: string, changeObject: Partial<I_table_sort<T>>) => void;
214
217
  changeSorts: (sorts: I_table_sort<T>[]) => Promise<void>;
215
- renderSortArrow: (option: I_table_sort<T> | false, inline?: boolean) => import("react/jsx-runtime").JSX.Element;
216
- getSortByColumn: (column: I_table_column<T>) => I_table_sort<T> | false;
218
+ renderSortArrow: (option: false | I_table_sort<T>, inline?: boolean) => import("react/jsx-runtime").JSX.Element;
219
+ getSortByColumn: (column: I_table_column<T>) => false | I_table_sort<T>;
217
220
  };
218
221
  export type I_table_paging = {
219
222
  serverSide?: boolean;
package/index.js CHANGED
@@ -58,7 +58,7 @@ const AIOTable = (props) => {
58
58
  }
59
59
  }
60
60
  const res = Object.assign(Object.assign({}, column), col);
61
- if (!res.value) {
61
+ if (res.value === undefined) {
62
62
  res.value = `row.${column.id}`;
63
63
  }
64
64
  return res;
@@ -95,25 +95,6 @@ const AIOTable = (props) => {
95
95
  props.onChangeColumns(newColumns);
96
96
  }
97
97
  }, 'aio-table-title');
98
- const getGetValue = (sort, column) => {
99
- if (sort.getValue) {
100
- return sort.getValue;
101
- }
102
- return (row) => {
103
- const { type = 'text' } = column;
104
- const cellValue = tableHook.getCellValue({ row, column, rowIndex: 0 });
105
- if (type === 'date' || type === 'jalaliDate') {
106
- const DATE = new AIODate();
107
- try {
108
- return DATE.getTime(cellValue);
109
- }
110
- catch (_a) {
111
- return 0;
112
- }
113
- }
114
- return cellValue;
115
- };
116
- };
117
98
  const getSorts = (columns) => {
118
99
  let sorts = [];
119
100
  for (let i = 0; i < columns.length; i++) {
@@ -124,11 +105,26 @@ const AIOTable = (props) => {
124
105
  if (!sort) {
125
106
  continue;
126
107
  }
127
- let { active = false, dir = 'dec', sortId } = sort;
128
- let sortItem = { dir, title: sort.title || column.title, sortId, active, getValue: getGetValue(sort, column) };
108
+ const { type = 'text' } = column;
109
+ let { active = false, dir = 'dec', sortId, order = Infinity } = sort;
110
+ let sortItem = {
111
+ isDate: type === 'date' || type === 'jalaliDate',
112
+ sortId, active, dir, columnId,
113
+ title: sort.title || column.title, order,
114
+ getValue: (row, dir) => {
115
+ if (sort.getValue) {
116
+ return sort.getValue(row, dir);
117
+ }
118
+ const cellValue = tableHook.getCellValue({ row, column, rowIndex: 0 });
119
+ if (column.type === 'number' && typeof cellValue !== 'number') {
120
+ return dir === 'inc' ? Infinity : -Infinity;
121
+ }
122
+ return cellValue;
123
+ }
124
+ };
129
125
  sorts.push(sortItem);
130
126
  }
131
- return sorts;
127
+ return UT.SortArray(sorts, [{ getValue: (o) => o.order, dir: 'inc' }]);
132
128
  };
133
129
  const sortHook = useSort({
134
130
  fa: props.fa,
@@ -598,7 +594,7 @@ export const useSort = (p) => {
598
594
  };
599
595
  const changeSorts = (sorts) => __awaiter(void 0, void 0, void 0, function* () {
600
596
  if (p.onChangeSort) {
601
- let res = yield p.onChangeSort(sorts);
597
+ let res = yield p.onChangeSort(sorts.filter((o) => !!o.active));
602
598
  if (res !== false) {
603
599
  setSorts(sorts);
604
600
  }
@@ -664,7 +660,7 @@ export const useSort = (p) => {
664
660
  return (_jsx(AISelect, { caret: false, options: sorts, justify: true, option: {
665
661
  text: (option) => option.title, checked: (option) => !!option.active, close: () => false, value: (option) => option.sortId,
666
662
  after: (option) => renderSortArrow(option),
667
- onClick: (option) => changeSort(option.sortId, { active: !option.active })
663
+ onClick: (option) => changeSort(option.sortId || '', { active: !option.active })
668
664
  }, popover: {
669
665
  header: { title: p.fa ? 'مرتب سازی' : 'Sort', onClose: false },
670
666
  headerAttrs: { className: 'aio-sort-header' },
@@ -735,7 +731,7 @@ const usePaging = (p) => {
735
731
  if (!sizes.length) {
736
732
  return null;
737
733
  }
738
- return (_jsx(AISelect, { attrs: { className: 'aio-paging-button aio-paging-size' }, value: size, options: sizes, option: { text: 'option', value: 'option' }, justify: true, onChange: (value) => changePaging({ size: value }), popover: { fitHorizontal: true } }));
734
+ return (_jsx(AISelect, { attrs: { className: 'aio-paging-button aio-paging-size' }, value: size, options: sizes, option: { text: (o) => o, value: (o) => o }, justify: true, onChange: (value) => changePaging({ size: value }), popover: { fitHorizontal: true } }));
739
735
  }
740
736
  const render = () => {
741
737
  const paging = getPaging(p.paging);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-table",
3
- "version": "14.0.1",
3
+ "version": "14.0.2",
4
4
  "description": "all in one table. tree mode , simple mode , tree mode, gantt mode , groupby mode, freeze mode.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",