aio-table 11.0.0 → 11.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.
package/index.css CHANGED
@@ -182,7 +182,10 @@
182
182
  border: none;
183
183
  background: none;
184
184
  }
185
-
185
+ .aio-table-toolbar-button .aio-input{
186
+ border:none;
187
+ background: none;
188
+ }
186
189
 
187
190
 
188
191
  .aio-table-remove {
package/index.d.ts CHANGED
@@ -45,6 +45,7 @@ export type I_table_column<T> = {
45
45
  show?: boolean;
46
46
  pattern?: string;
47
47
  data?: any;
48
+ toggle?: boolean;
48
49
  };
49
50
  export type I_table<T> = {
50
51
  fa?: boolean;
package/index.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { createContext, createRef, Fragment, useContext, useEffect, useRef, useState } from "react";
12
- import AIOInput from "aio-input";
12
+ import AIOInput, { AISelect } from "aio-input";
13
13
  import * as UT from 'aio-utils';
14
14
  import usePopup from "aio-popup";
15
15
  import AIODate from "aio-date";
@@ -24,6 +24,7 @@ const AIOTable = (props) => {
24
24
  const [searchColumns, setSearchColumns] = useState([]);
25
25
  const [excelColumns, setExcelColumns] = useState([]);
26
26
  const [filterColumns, setFilterColumns] = useState([]);
27
+ const [toggleColumns, setToggleColumns] = useState([]);
27
28
  const filterColumnsRef = useRef(filterColumns);
28
29
  filterColumnsRef.current = filterColumns;
29
30
  const rowsIndexDicRef = useRef({});
@@ -33,6 +34,9 @@ const AIOTable = (props) => {
33
34
  propsRef.current = props;
34
35
  const pagingHook = UT.usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
35
36
  const getColumnOption = (key, cellDetails) => {
37
+ if (key === 'id') {
38
+ return cellDetails.column.id;
39
+ }
36
40
  const columnValue = cellDetails.column[key];
37
41
  if (columnValue !== undefined) {
38
42
  const { getValue = {} } = props;
@@ -61,7 +65,7 @@ const AIOTable = (props) => {
61
65
  if (props.onChangeColumns) {
62
66
  props.onChangeColumns(newColumns);
63
67
  }
64
- }, 'aio-table-title', 'aio-table-unit');
68
+ }, 'aio-table-title');
65
69
  const getGetValue = (sort, column) => {
66
70
  if (sort.getValue) {
67
71
  return sort.getValue;
@@ -108,12 +112,13 @@ const AIOTable = (props) => {
108
112
  });
109
113
  function getColumns() {
110
114
  let { columns = [] } = props;
111
- let searchColumns = [], excelColumns = [], filterColumns = [];
115
+ let searchColumns = [], excelColumns = [], filterColumns = [], toggleColumns = [];
112
116
  let updatedColumns = columns.map((column, i) => {
113
117
  const cellDetail = tableHook.getCellDetail({ column });
114
118
  const filterId = getColumnOption('filterId', cellDetail);
115
119
  const search = getColumnOption('search', cellDetail);
116
120
  const excel = getColumnOption('excel', cellDetail);
121
+ const toggle = getColumnOption('toggle', cellDetail);
117
122
  const id = getColumnOption('id', cellDetail);
118
123
  if (id === undefined) {
119
124
  console.error(`aio-table error => missing column id in props.columns[${i}]`);
@@ -127,6 +132,9 @@ const AIOTable = (props) => {
127
132
  if (filterId) {
128
133
  filterColumns.push(column);
129
134
  }
135
+ if (toggle) {
136
+ toggleColumns.push(column);
137
+ }
130
138
  return column;
131
139
  });
132
140
  if (props.onChangeColumns) {
@@ -135,6 +143,7 @@ const AIOTable = (props) => {
135
143
  setSearchColumns(searchColumns);
136
144
  setExcelColumns(excelColumns);
137
145
  setFilterColumns(filterColumns);
146
+ setToggleColumns(toggleColumns);
138
147
  return updatedColumns;
139
148
  }
140
149
  useEffect(() => {
@@ -253,7 +262,7 @@ const AIOTable = (props) => {
253
262
  const { gap = [0, 1] } = props;
254
263
  let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
255
264
  const context = {
256
- rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS,
265
+ rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS, toggleColumns,
257
266
  getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup, getColumnOption
258
267
  };
259
268
  return (_jsxs(Provider, { value: context, children: [_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, {}), !!props.filter &&
@@ -302,10 +311,12 @@ const TableRows = () => {
302
311
  return _jsx("div", { className: 'aio-table-rows', style: { gap: gap[1] }, children: content });
303
312
  };
304
313
  const TableToolbar = () => {
305
- let { add, exportToExcel, search, rootProps, excelColumns, getIcon, sortHook } = useProvider();
306
- let { toolbarAttrs, toolbar, onAdd, onSearch, value } = rootProps;
314
+ let { add, exportToExcel, search, rootProps, excelColumns, toggleColumns, getIcon, sortHook, getColumnOption, tableHook } = useProvider();
315
+ let { toolbarAttrs, toolbar, onAdd, onSearch, value, onChangeColumns, columns = [] } = rootProps;
316
+ const columnsRef = useRef(columns);
317
+ columnsRef.current = columns;
307
318
  toolbarAttrs = UT.AddToAttrs(toolbarAttrs, { className: 'aio-table-toolbar' });
308
- if (!onAdd && !toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length) {
319
+ if (!onAdd && !toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length && !toggleColumns.length) {
309
320
  return null;
310
321
  }
311
322
  function getAddText() {
@@ -315,8 +326,25 @@ const TableToolbar = () => {
315
326
  }
316
327
  return typeof addText === 'function' ? addText(value) : addText;
317
328
  }
329
+ const getColumnOptionWrapper = (columnId, key) => {
330
+ const columns = columnsRef.current || [];
331
+ const column = columns.find((o) => o.id === columnId);
332
+ return getColumnOption(key, tableHook.getCellDetail({ column }));
333
+ };
318
334
  return (_jsxs("div", Object.assign({}, toolbarAttrs, { children: [toolbar && _jsx("div", { className: 'aio-table-toolbar-content', children: typeof toolbar === 'function' ? toolbar() : toolbar }), !!onSearch &&
319
- _jsx("div", { className: 'aio-table-search', children: _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => add(), children: getAddText() })] })));
335
+ _jsx("div", { className: 'aio-table-search', children: _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button aio-table-excel-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!toggleColumns.length &&
336
+ _jsx("div", { className: 'aio-table-toolbar-button aio-table-toggle-button', children: _jsx(AISelect, { text: getIcon('mdiEye', 0.8), hideTags: true, options: toggleColumns, caret: false, option: {
337
+ text: (column) => getColumnOptionWrapper(column.id, 'title'),
338
+ checked: (column) => getColumnOptionWrapper(column.id, 'show'),
339
+ onClick: (column) => {
340
+ if (!onChangeColumns) {
341
+ return;
342
+ }
343
+ const columns = columnsRef.current || [];
344
+ onChangeColumns(columns.map((o) => column.id === o.id ? Object.assign(Object.assign({}, o), { show: !getColumnOptionWrapper(o.id, 'show') }) : o));
345
+ },
346
+ close: () => false
347
+ } }) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button aio-table-add-button', onClick: () => add(), children: getAddText() })] })));
320
348
  };
321
349
  const TableHeader = () => {
322
350
  let { rootProps, getColumnOption, tableHook } = useProvider();
@@ -414,7 +442,7 @@ const useTable = (getProps, getPaging, getColumnOption) => {
414
442
  else if (onChange) {
415
443
  onChange(newRows);
416
444
  }
417
- }, 'aio-table-row', 'aio-table-rows');
445
+ }, 'aio-table-row');
418
446
  const getCellValue = (cellDetail, cellValue, def) => {
419
447
  const { getValue = {} } = getProps();
420
448
  const paging = getPaging();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-table",
3
- "version": "11.0.0",
3
+ "version": "11.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",