bitys-react-components 0.1.7 → 0.1.8
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/README.md +54 -2
- package/dist/DataGridView/components/ADPagination.js +98 -0
- package/dist/DataGridView/components/Pagination.js +72 -0
- package/dist/DataGridView/components/TableFooter.js +59 -0
- package/dist/DataGridView/components/TableHeader.js +124 -0
- package/dist/DataGridView/index.js +701 -0
- package/dist/DataGridView/style/index.js +45 -0
- package/dist/index.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,54 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# Bitys React Components
|
|
2
|
+
|
|
3
|
+
Biblioteca de componentes reutilizáveis para React, com suporte a Bootstrap 5 e styled-components.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Instalação
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install bitys-react-components
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Peer dependencies:** `react`, `react-dom`, `bootstrap`, `reactstrap`, `react-icons`, `styled-components`
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Componentes
|
|
18
|
+
|
|
19
|
+
### CardFilter
|
|
20
|
+
|
|
21
|
+
Card colapsável para agrupar filtros de busca. Inclui botão "Buscar" e toggle para expandir/recolher o conteúdo. Ideal para telas de listagem com critérios de filtro.
|
|
22
|
+
|
|
23
|
+
### InputCheck
|
|
24
|
+
|
|
25
|
+
Checkbox estilizado com label opcional. Aceita `value`, `onChange` e demais props nativas de input, com suporte a customização via estilos no container e no label.
|
|
26
|
+
|
|
27
|
+
### DataGridView
|
|
28
|
+
|
|
29
|
+
Tabela de dados completa com ordenação por coluna, paginação (básica ou avançada), busca em tempo real e exportação (Excel, CSV, PDF). Configurável por `config` (idioma, botões, tamanho de página, etc.) e colunas definidas via `columns` + `data`.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Uso básico
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { CardFilter, InputCheck, DataGridView } from 'bitys-react-components';
|
|
37
|
+
|
|
38
|
+
// CardFilter: envolva seus campos de filtro
|
|
39
|
+
<CardFilter onChange={handleSearch}>
|
|
40
|
+
<input type="text" placeholder="Nome" />
|
|
41
|
+
</CardFilter>
|
|
42
|
+
|
|
43
|
+
// InputCheck: checkbox com label
|
|
44
|
+
<InputCheck label="Aceito os termos" value={checked} onChange={handleChange} />
|
|
45
|
+
|
|
46
|
+
// DataGridView: tabela com columns e data
|
|
47
|
+
<DataGridView columns={columns} data={rows} config={config} onChange={handleChange} />
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Licença
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = ADPagination;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
function ADPagination(props) {
|
|
11
|
+
var size = props.pages;
|
|
12
|
+
var page = props.page_number;
|
|
13
|
+
var step = 2;
|
|
14
|
+
var tags = [];
|
|
15
|
+
var pagination = props.language.pagination;
|
|
16
|
+
var Item = function Item(props) {
|
|
17
|
+
var className = props.className || "";
|
|
18
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
19
|
+
className: "page-item " + className,
|
|
20
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
21
|
+
href: "#",
|
|
22
|
+
className: "page-link",
|
|
23
|
+
tabIndex: "-1",
|
|
24
|
+
onClick: function onClick(e) {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
props.onClick(e);
|
|
27
|
+
},
|
|
28
|
+
children: props.children
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var Add = function Add(s, f) {
|
|
33
|
+
var _loop = function _loop(i) {
|
|
34
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
35
|
+
className: page == i ? "active" : "",
|
|
36
|
+
onClick: function onClick(e) {
|
|
37
|
+
return props.goToPage(e, i);
|
|
38
|
+
},
|
|
39
|
+
children: i
|
|
40
|
+
}, i));
|
|
41
|
+
};
|
|
42
|
+
for (var i = s; i < f; i++) {
|
|
43
|
+
_loop(i);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var Last = function Last() {
|
|
47
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
48
|
+
children: "..."
|
|
49
|
+
}, "l..."));
|
|
50
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
51
|
+
className: page == size ? "active" : "",
|
|
52
|
+
onClick: function onClick(e) {
|
|
53
|
+
return props.goToPage(e, size);
|
|
54
|
+
},
|
|
55
|
+
children: size
|
|
56
|
+
}, size));
|
|
57
|
+
};
|
|
58
|
+
var First = function First() {
|
|
59
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
60
|
+
className: page == 1 ? "active" : "",
|
|
61
|
+
onClick: function onClick(e) {
|
|
62
|
+
return props.goToPage(e, 1);
|
|
63
|
+
},
|
|
64
|
+
children: "1"
|
|
65
|
+
}, "1"));
|
|
66
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
67
|
+
children: "..."
|
|
68
|
+
}, "f..."));
|
|
69
|
+
};
|
|
70
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
71
|
+
className: props.isFirst ? "disabled " : "",
|
|
72
|
+
onClick: props.previousPage,
|
|
73
|
+
children: pagination.previous ? pagination.previous : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
74
|
+
children: "\u25C4"
|
|
75
|
+
})
|
|
76
|
+
}, "p0"));
|
|
77
|
+
if (size < step * 2 + 6) {
|
|
78
|
+
Add(1, size + 1);
|
|
79
|
+
} else if (page < step * 2 + 1) {
|
|
80
|
+
Add(1, step * 2 + 4);
|
|
81
|
+
Last();
|
|
82
|
+
} else if (page > size - step * 2) {
|
|
83
|
+
First();
|
|
84
|
+
Add(size - step * 2 - 2, size + 1);
|
|
85
|
+
} else {
|
|
86
|
+
First();
|
|
87
|
+
Add(page - step, page + step + 1);
|
|
88
|
+
Last();
|
|
89
|
+
}
|
|
90
|
+
tags.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, {
|
|
91
|
+
className: props.isLast ? "disabled " : "",
|
|
92
|
+
onClick: props.nextPage,
|
|
93
|
+
children: pagination.next ? pagination.next : /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
94
|
+
children: "\u25BA"
|
|
95
|
+
})
|
|
96
|
+
}, "n0"));
|
|
97
|
+
return tags;
|
|
98
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = InitialPagination;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
12
|
+
function InitialPagination(props) {
|
|
13
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
|
|
14
|
+
children: [props.config.show_first ? /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
15
|
+
className: (props.isFirst ? "disabled " : "") + "page-item",
|
|
16
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
17
|
+
href: "#",
|
|
18
|
+
className: "page-link",
|
|
19
|
+
tabIndex: "-1",
|
|
20
|
+
onClick: props.firstPage,
|
|
21
|
+
children: props.config.language.pagination.first
|
|
22
|
+
})
|
|
23
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
24
|
+
className: (props.isFirst ? "disabled " : "") + "page-item",
|
|
25
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
26
|
+
href: "#",
|
|
27
|
+
className: "page-link",
|
|
28
|
+
tabIndex: "-1",
|
|
29
|
+
onClick: props.previousPage,
|
|
30
|
+
children: props.config.language.pagination.previous
|
|
31
|
+
})
|
|
32
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
33
|
+
className: "page-item",
|
|
34
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
35
|
+
className: "page-link",
|
|
36
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
37
|
+
style: {
|
|
38
|
+
border: 'none',
|
|
39
|
+
padding: '0',
|
|
40
|
+
maxWidth: '30px',
|
|
41
|
+
textAlign: 'center',
|
|
42
|
+
display: 'inline-block'
|
|
43
|
+
},
|
|
44
|
+
type: "text",
|
|
45
|
+
value: props.is_temp_page ? props.temp_page_number : props.page_number,
|
|
46
|
+
onChange: function onChange(e) {
|
|
47
|
+
return props.onPageChange(e, true);
|
|
48
|
+
},
|
|
49
|
+
onBlur: props.onPageBlur,
|
|
50
|
+
onKeyDown: props.onPageChange
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
54
|
+
className: (props.isLast ? "disabled " : "") + "page-item",
|
|
55
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
56
|
+
href: "#",
|
|
57
|
+
className: "page-link",
|
|
58
|
+
onClick: props.nextPage,
|
|
59
|
+
children: props.config.language.pagination.next
|
|
60
|
+
})
|
|
61
|
+
}), props.config.show_last ? /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
62
|
+
className: (props.isLast ? "disabled " : "") + "page-item",
|
|
63
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
|
|
64
|
+
href: "#",
|
|
65
|
+
className: "page-link",
|
|
66
|
+
tabIndex: "-1",
|
|
67
|
+
onClick: props.lastPage,
|
|
68
|
+
children: props.config.language.pagination.last
|
|
69
|
+
})
|
|
70
|
+
}) : null]
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = TableFooter;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _Pagination = _interopRequireDefault(require("./Pagination"));
|
|
9
|
+
var _ADPagination = _interopRequireDefault(require("./ADPagination"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function TableFooter(props) {
|
|
13
|
+
if (props.config.show_info == true || props.config.show_pagination == true) {
|
|
14
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
15
|
+
className: "row table-foot asrt-table-foot",
|
|
16
|
+
id: props.id ? props.id + "-table-foot" : "",
|
|
17
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
className: "col-md-6",
|
|
19
|
+
children: props.config.show_info ? props.paginationInfo : null
|
|
20
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
21
|
+
className: "col-md-6 pull-right text-right",
|
|
22
|
+
children: props.config.show_pagination ? /*#__PURE__*/(0, _jsxRuntime.jsx)("nav", {
|
|
23
|
+
"aria-label": "Page navigation",
|
|
24
|
+
className: "pull-right",
|
|
25
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("ul", {
|
|
26
|
+
className: "pagination justify-content-end asrt-pagination",
|
|
27
|
+
children: props.config.pagination == "basic" ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Pagination["default"], {
|
|
28
|
+
config: props.config,
|
|
29
|
+
isFirst: props.isFirst,
|
|
30
|
+
isLast: props.isLast,
|
|
31
|
+
pages: props.pages,
|
|
32
|
+
page_number: props.page_number,
|
|
33
|
+
is_temp_page: props.is_temp_page,
|
|
34
|
+
temp_page_number: props.temp_page_number,
|
|
35
|
+
previousPage: props.previousPage,
|
|
36
|
+
firstPage: props.firstPage,
|
|
37
|
+
nextPage: props.nextPage,
|
|
38
|
+
lastPage: props.lastPage,
|
|
39
|
+
goToPage: props.goToPage,
|
|
40
|
+
onPageChange: props.onPageChange,
|
|
41
|
+
onPageBlur: props.onPageBlur
|
|
42
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ADPagination["default"], {
|
|
43
|
+
language: props.config.language,
|
|
44
|
+
isFirst: props.isFirst,
|
|
45
|
+
isLast: props.isLast,
|
|
46
|
+
pages: props.pages,
|
|
47
|
+
page_number: props.page_number,
|
|
48
|
+
previousPage: props.previousPage,
|
|
49
|
+
nextPage: props.nextPage,
|
|
50
|
+
goToPage: props.goToPage
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}) : null
|
|
54
|
+
})]
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = TableHeader;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _includes = _interopRequireDefault(require("lodash/includes"));
|
|
9
|
+
var _style = _interopRequireDefault(require("../style"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function TableHeader(props) {
|
|
13
|
+
if (props.config.show_length_menu == true || props.config.show_filter == true || props.config.button.excel == true || props.config.button.csv == true || props.config.button.print == true) {
|
|
14
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
15
|
+
className: "row table-head asrt-table-head",
|
|
16
|
+
id: props.id ? props.id + "-table-head" : "",
|
|
17
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
18
|
+
className: "col-md-6",
|
|
19
|
+
children: props.config.show_length_menu ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
20
|
+
className: "input-group asrt-page-length",
|
|
21
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
22
|
+
className: "input-group-addon input-group-prepend",
|
|
23
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
24
|
+
className: "input-group-text",
|
|
25
|
+
style: _style["default"].table_size,
|
|
26
|
+
children: props.lengthMenuText[0] ? props.lengthMenuText[0] : ''
|
|
27
|
+
})
|
|
28
|
+
}), (0, _includes["default"])(props.config.language.length_menu, '_MENU_') ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("select", {
|
|
29
|
+
type: "text",
|
|
30
|
+
className: "form-control",
|
|
31
|
+
style: _style["default"].table_size_dropdown,
|
|
32
|
+
onChange: props.changePageSize,
|
|
33
|
+
children: [props.config.length_menu.map(function (value, key) {
|
|
34
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
|
|
35
|
+
children: value
|
|
36
|
+
}, value);
|
|
37
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("option", {
|
|
38
|
+
value: props.recordLength,
|
|
39
|
+
children: "All"
|
|
40
|
+
})]
|
|
41
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
42
|
+
className: "input-group-addon input-group-prepend",
|
|
43
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
44
|
+
className: "input-group-text",
|
|
45
|
+
style: _style["default"].table_size,
|
|
46
|
+
children: props.lengthMenuText[1] ? props.lengthMenuText[1] : ''
|
|
47
|
+
})
|
|
48
|
+
})]
|
|
49
|
+
}) : null
|
|
50
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
51
|
+
className: "col-md-6 float-right text-right",
|
|
52
|
+
children: [props.config.show_filter ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
53
|
+
className: "table_filter",
|
|
54
|
+
style: _style["default"].table_filter,
|
|
55
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
|
|
56
|
+
type: "search",
|
|
57
|
+
className: "form-control",
|
|
58
|
+
placeholder: props.config.language.filter,
|
|
59
|
+
onChange: props.filterRecords
|
|
60
|
+
})
|
|
61
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
62
|
+
className: "table_tools",
|
|
63
|
+
style: _style["default"].table_tool,
|
|
64
|
+
children: [props.config.button.excel ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
65
|
+
className: "btn btn-primary buttons-excel",
|
|
66
|
+
tabIndex: "0",
|
|
67
|
+
"aria-controls": "configuration_tbl",
|
|
68
|
+
title: "Export to Excel",
|
|
69
|
+
style: _style["default"].table_tool_btn,
|
|
70
|
+
onClick: props.exportToExcel,
|
|
71
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
72
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
|
|
73
|
+
className: "fa fa-file-excel-o",
|
|
74
|
+
"aria-hidden": "true"
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}) : null, props.config.button.csv ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
78
|
+
className: "btn btn-primary buttons-csv",
|
|
79
|
+
tabIndex: "0",
|
|
80
|
+
"aria-controls": "configuration_tbl",
|
|
81
|
+
title: "Export to CSV",
|
|
82
|
+
style: _style["default"].table_tool_btn,
|
|
83
|
+
onClick: props.exportToCSV,
|
|
84
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
85
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
|
|
86
|
+
className: "fa fa-file-text-o",
|
|
87
|
+
"aria-hidden": "true"
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
}) : null, props.config.button.print ? /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
91
|
+
className: "btn btn-primary buttons-pdf",
|
|
92
|
+
tabIndex: "0",
|
|
93
|
+
"aria-controls": "configuration_tbl",
|
|
94
|
+
title: "Export to PDF",
|
|
95
|
+
style: _style["default"].table_tool_btn,
|
|
96
|
+
onClick: props.exportToPDF,
|
|
97
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
98
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
|
|
99
|
+
className: "glyphicon glyphicon-print fa fa-print",
|
|
100
|
+
"aria-hidden": "true"
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
}) : null, props.config.button.extra == true ? props.extraButtons.map(function (elem, index) {
|
|
104
|
+
elem.clickCount = 0;
|
|
105
|
+
elem.singleClickTimer = '';
|
|
106
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
107
|
+
className: elem.className ? elem.className : "btn btn-primary buttons-pdf",
|
|
108
|
+
tabIndex: "0",
|
|
109
|
+
"aria-controls": "configuration_tbl",
|
|
110
|
+
title: elem.title ? elem.title : "Export to PDF",
|
|
111
|
+
style: _style["default"].table_tool_btn,
|
|
112
|
+
onClick: function onClick(event) {
|
|
113
|
+
elem.onClick(event);
|
|
114
|
+
},
|
|
115
|
+
children: elem.children
|
|
116
|
+
}, index);
|
|
117
|
+
}) : null]
|
|
118
|
+
})]
|
|
119
|
+
})]
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _server = _interopRequireDefault(require("react-dom/server"));
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
+
require("./assets/css/style.css");
|
|
11
|
+
var _TableHeader = _interopRequireDefault(require("./components/TableHeader"));
|
|
12
|
+
var _TableFooter = _interopRequireDefault(require("./components/TableFooter"));
|
|
13
|
+
var _style2 = _interopRequireDefault(require("./style"));
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
18
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
19
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
20
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
21
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
24
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
25
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
28
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
29
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
30
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
31
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
32
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
33
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
34
|
+
var ReactDatatable = /*#__PURE__*/function (_Component) {
|
|
35
|
+
function ReactDatatable(props) {
|
|
36
|
+
var _this;
|
|
37
|
+
_classCallCheck(this, ReactDatatable);
|
|
38
|
+
_this = _callSuper(this, ReactDatatable, [props]);
|
|
39
|
+
_this.exportExcelRef = /*#__PURE__*/_react["default"].createRef();
|
|
40
|
+
_this.sortColumn = _this.sortColumn.bind(_this);
|
|
41
|
+
_this.numPages = _this.numPages.bind(_this);
|
|
42
|
+
_this.exportToExcel = _this.exportToExcel.bind(_this);
|
|
43
|
+
_this.exportToPDF = _this.exportToPDF.bind(_this);
|
|
44
|
+
_this.exportToCSV = _this.exportToCSV.bind(_this);
|
|
45
|
+
_this.onChange = _this.onChange.bind(_this);
|
|
46
|
+
_this.filterRecords = _this.filterRecords.bind(_this);
|
|
47
|
+
_this.filterData = _this.filterData.bind(_this);
|
|
48
|
+
_this.sortRecords = _this.sortRecords.bind(_this);
|
|
49
|
+
_this.config = {
|
|
50
|
+
button: {
|
|
51
|
+
excel: props.config && props.config.button && props.config.button.excel ? props.config.button.excel : false,
|
|
52
|
+
print: props.config && props.config.button && props.config.button.print ? props.config.button.print : false,
|
|
53
|
+
csv: props.config && props.config.button && props.config.button.csv ? props.config.button.csv : false,
|
|
54
|
+
extra: props.config && props.config.button && props.config.button.extra ? props.config.button.extra : false
|
|
55
|
+
},
|
|
56
|
+
filename: props.config && props.config.filename ? props.config.filename : 'table',
|
|
57
|
+
key_column: props.config && props.config.key_column ? props.config.key_column : 'id',
|
|
58
|
+
language: {
|
|
59
|
+
length_menu: props.config && props.config.language && props.config.language.length_menu ? props.config.language.length_menu : 'Show _MENU_ records per page',
|
|
60
|
+
filter: props.config && props.config.language && props.config.language.filter ? props.config.language.filter : 'Search in records...',
|
|
61
|
+
info: props.config && props.config.language && props.config.language.info ? props.config.language.info : 'Showing _START_ to _END_ of _TOTAL_ entries',
|
|
62
|
+
pagination: {
|
|
63
|
+
first: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.first ? props.config.language.pagination.first : 'First',
|
|
64
|
+
previous: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.previous ? props.config.language.pagination.previous : 'Previous',
|
|
65
|
+
next: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.next ? props.config.language.pagination.next : 'Next',
|
|
66
|
+
last: props.config && props.config.language && props.config.language.pagination && props.config.language.pagination.last ? props.config.language.pagination.last : 'Last'
|
|
67
|
+
},
|
|
68
|
+
no_data_text: props.config && props.config.language && props.config.language.no_data_text ? props.config.language.no_data_text : 'No rows found',
|
|
69
|
+
loading_text: props.config && props.config.language && props.config.language.loading_text ? props.config.language.loading_text : 'Loading...'
|
|
70
|
+
},
|
|
71
|
+
length_menu: props.config && props.config.length_menu ? props.config.length_menu : [10, 25, 50, 75, 100],
|
|
72
|
+
show_length_menu: props.config.show_length_menu != undefined ? props.config.show_length_menu : true,
|
|
73
|
+
show_filter: props.config.show_filter != undefined ? props.config.show_filter : true,
|
|
74
|
+
show_pagination: props.config.show_pagination != undefined ? props.config.show_pagination : true,
|
|
75
|
+
show_info: props.config.show_info != undefined ? props.config.show_info : true,
|
|
76
|
+
show_first: props.config.show_first != undefined ? props.config.show_first : true,
|
|
77
|
+
show_last: props.config.show_last != undefined ? props.config.show_last : true,
|
|
78
|
+
pagination: props.config.pagination ? props.config.pagination : 'basic'
|
|
79
|
+
};
|
|
80
|
+
_this.state = {
|
|
81
|
+
is_temp_page: false,
|
|
82
|
+
filter_value: '',
|
|
83
|
+
page_size: props.config.page_size ? props.config.page_size : 10,
|
|
84
|
+
page_number: 1,
|
|
85
|
+
sort: props.config && props.config.sort ? props.config.sort : false
|
|
86
|
+
};
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
_inherits(ReactDatatable, _Component);
|
|
90
|
+
return _createClass(ReactDatatable, [{
|
|
91
|
+
key: "filterRecords",
|
|
92
|
+
value: function filterRecords(e) {
|
|
93
|
+
var _this2 = this;
|
|
94
|
+
var value = e.target.value;
|
|
95
|
+
this.setState({
|
|
96
|
+
page_number: 1,
|
|
97
|
+
filter_value: value
|
|
98
|
+
}, function () {
|
|
99
|
+
_this2.onChange();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "changePageSize",
|
|
104
|
+
value: function changePageSize(e) {
|
|
105
|
+
var _this3 = this;
|
|
106
|
+
var value = e.target.value;
|
|
107
|
+
this.setState({
|
|
108
|
+
page_size: value
|
|
109
|
+
}, function () {
|
|
110
|
+
_this3.onChange();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "sortColumn",
|
|
115
|
+
value: function sortColumn(event, column, sortOrder) {
|
|
116
|
+
var _this4 = this;
|
|
117
|
+
if (!column.sortable) return false;
|
|
118
|
+
var newSortOrder = sortOrder == 'asc' ? 'desc' : 'asc';
|
|
119
|
+
this.setState({
|
|
120
|
+
sort: {
|
|
121
|
+
column: column.key,
|
|
122
|
+
order: newSortOrder
|
|
123
|
+
}
|
|
124
|
+
}, function () {
|
|
125
|
+
_this4.onChange();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "paginate",
|
|
130
|
+
value: function paginate(records) {
|
|
131
|
+
var page_size = this.state.page_size;
|
|
132
|
+
var page_number = this.state.page_number;
|
|
133
|
+
--page_number; // because pages logically start with 1, but technically with 0
|
|
134
|
+
return records.slice(page_number * page_size, (page_number + 1) * page_size);
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "numPages",
|
|
138
|
+
value: function numPages(totalRecord) {
|
|
139
|
+
return Math.ceil(totalRecord / this.state.page_size);
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "isLast",
|
|
143
|
+
value: function isLast() {
|
|
144
|
+
// because for empty records page_number will still be 1
|
|
145
|
+
if (this.pages == 0) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (this.state.page_number == this.pages) {
|
|
149
|
+
return true;
|
|
150
|
+
} else {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}, {
|
|
155
|
+
key: "isFirst",
|
|
156
|
+
value: function isFirst() {
|
|
157
|
+
if (this.state.page_number == 1) {
|
|
158
|
+
return true;
|
|
159
|
+
} else {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}, {
|
|
164
|
+
key: "goToPage",
|
|
165
|
+
value: function goToPage(e, pageNumber) {
|
|
166
|
+
var _this5 = this;
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
if (this.state.page_number == pageNumber) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var pageState = {
|
|
172
|
+
previous_page: this.state.page_number,
|
|
173
|
+
current_page: pageNumber
|
|
174
|
+
};
|
|
175
|
+
this.setState({
|
|
176
|
+
is_temp_page: false,
|
|
177
|
+
page_number: pageNumber
|
|
178
|
+
}, function () {
|
|
179
|
+
_this5.props.onPageChange(pageState);
|
|
180
|
+
_this5.onChange();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "firstPage",
|
|
185
|
+
value: function firstPage(e) {
|
|
186
|
+
e.preventDefault();
|
|
187
|
+
if (this.isFirst()) return;
|
|
188
|
+
this.goToPage(e, 1);
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "lastPage",
|
|
192
|
+
value: function lastPage(e) {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
if (this.isLast()) return;
|
|
195
|
+
this.goToPage(e, this.pages);
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "previousPage",
|
|
199
|
+
value: function previousPage(e) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
if (this.isFirst()) return false;
|
|
202
|
+
this.goToPage(e, this.state.page_number - 1);
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "nextPage",
|
|
206
|
+
value: function nextPage(e) {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
if (this.isLast()) return;
|
|
209
|
+
this.goToPage(e, parseInt(this.state.page_number) + 1);
|
|
210
|
+
}
|
|
211
|
+
}, {
|
|
212
|
+
key: "onPageChange",
|
|
213
|
+
value: function onPageChange(e) {
|
|
214
|
+
var isInputChange = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
215
|
+
if (isInputChange) {
|
|
216
|
+
this.setState({
|
|
217
|
+
is_temp_page: true,
|
|
218
|
+
temp_page_number: e.target.value
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
if (e.key === 'Enter') {
|
|
222
|
+
var pageNumber = e.target.value;
|
|
223
|
+
this.goToPage(e, pageNumber);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}, {
|
|
228
|
+
key: "onPageBlur",
|
|
229
|
+
value: function onPageBlur(e) {
|
|
230
|
+
var pageNumber = e.target.value;
|
|
231
|
+
this.goToPage(e, pageNumber);
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "strip",
|
|
235
|
+
value: function strip(html) {
|
|
236
|
+
var doc = new DOMParser().parseFromString(html, 'text/html');
|
|
237
|
+
return doc.body.textContent || '';
|
|
238
|
+
}
|
|
239
|
+
}, {
|
|
240
|
+
key: "getExportHtml",
|
|
241
|
+
value: function getExportHtml() {
|
|
242
|
+
var tableHtml = '<table>';
|
|
243
|
+
tableHtml += '<thead>';
|
|
244
|
+
tableHtml += '<tr>';
|
|
245
|
+
var _iterator = _createForOfIteratorHelper(this.props.columns),
|
|
246
|
+
_step;
|
|
247
|
+
try {
|
|
248
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
249
|
+
var _column = _step.value;
|
|
250
|
+
tableHtml += '<th>' + _column.text + '</th>';
|
|
251
|
+
}
|
|
252
|
+
} catch (err) {
|
|
253
|
+
_iterator.e(err);
|
|
254
|
+
} finally {
|
|
255
|
+
_iterator.f();
|
|
256
|
+
}
|
|
257
|
+
tableHtml += '</tr>';
|
|
258
|
+
tableHtml += '</thead>';
|
|
259
|
+
tableHtml += '<tbody>';
|
|
260
|
+
|
|
261
|
+
// Filter records before export
|
|
262
|
+
var filterRecords = this.props.records;
|
|
263
|
+
if (this.props.dynamic === false) {
|
|
264
|
+
var records = this.sortRecords(),
|
|
265
|
+
filterValue = this.state.filter_value;
|
|
266
|
+
filterRecords = records;
|
|
267
|
+
if (filterValue) {
|
|
268
|
+
filterRecords = this.filterData(records);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
for (var i in filterRecords) {
|
|
272
|
+
var record = filterRecords[i];
|
|
273
|
+
tableHtml += '<tr>';
|
|
274
|
+
var _iterator2 = _createForOfIteratorHelper(this.props.columns),
|
|
275
|
+
_step2;
|
|
276
|
+
try {
|
|
277
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
278
|
+
var column = _step2.value;
|
|
279
|
+
if (column.cell && typeof column.cell === 'function') {
|
|
280
|
+
var cellData = _server["default"].renderToStaticMarkup(column.cell(record, i));
|
|
281
|
+
cellData = this.strip(cellData);
|
|
282
|
+
tableHtml += '<td>' + cellData + '</td>';
|
|
283
|
+
} else if (record[column.key]) {
|
|
284
|
+
tableHtml += '<td>' + record[column.key] + '</td>';
|
|
285
|
+
} else {
|
|
286
|
+
tableHtml += '<td></td>';
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
} catch (err) {
|
|
290
|
+
_iterator2.e(err);
|
|
291
|
+
} finally {
|
|
292
|
+
_iterator2.f();
|
|
293
|
+
}
|
|
294
|
+
tableHtml += '</tr>';
|
|
295
|
+
}
|
|
296
|
+
tableHtml += '</tbody>';
|
|
297
|
+
tableHtml += '</table>';
|
|
298
|
+
return tableHtml;
|
|
299
|
+
}
|
|
300
|
+
}, {
|
|
301
|
+
key: "exportToExcel",
|
|
302
|
+
value: function exportToExcel() {
|
|
303
|
+
var downloadLink,
|
|
304
|
+
dataType = 'application/vnd.ms-excel';
|
|
305
|
+
var tableHtml = this.getExportHtml();
|
|
306
|
+
|
|
307
|
+
// Specify file name
|
|
308
|
+
var filename = this.config.filename ? this.config.filename + '.xls' : 'table.xls';
|
|
309
|
+
// Create download link element
|
|
310
|
+
downloadLink = document.createElement('a');
|
|
311
|
+
if (navigator.msSaveOrOpenBlob) {
|
|
312
|
+
var blob = new Blob(["\uFEFF", tableHtml], {
|
|
313
|
+
type: dataType
|
|
314
|
+
});
|
|
315
|
+
navigator.msSaveOrOpenBlob(blob, filename);
|
|
316
|
+
} else {
|
|
317
|
+
// Create a link to the file
|
|
318
|
+
downloadLink.href = 'data:' + dataType + ', ' + tableHtml;
|
|
319
|
+
// Setting the file name
|
|
320
|
+
downloadLink.download = filename;
|
|
321
|
+
//triggering the function
|
|
322
|
+
downloadLink.click();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
key: "exportToPDF",
|
|
327
|
+
value: function exportToPDF() {
|
|
328
|
+
var tableHtml = this.getExportHtml();
|
|
329
|
+
var style = '<style>';
|
|
330
|
+
style = style + 'table {width: 100%;font: 17px Calibri;}';
|
|
331
|
+
style = style + 'table, th, td {border: solid 1px #DDD; border-collapse: collapse;';
|
|
332
|
+
style = style + 'padding: 2px 3px;text-align:left;}';
|
|
333
|
+
style = style + '</style>';
|
|
334
|
+
var win = window.open('', '_blank');
|
|
335
|
+
win.document.write('<html><head>');
|
|
336
|
+
win.document.write('<title>' + this.config.filename + '</title>');
|
|
337
|
+
win.document.write(style);
|
|
338
|
+
win.document.write('</head>');
|
|
339
|
+
win.document.write('<body>');
|
|
340
|
+
win.document.write('<h1>' + this.config.filename + '</h1>');
|
|
341
|
+
win.document.write(tableHtml);
|
|
342
|
+
win.document.write('</body></html>');
|
|
343
|
+
win.print();
|
|
344
|
+
win.close();
|
|
345
|
+
}
|
|
346
|
+
}, {
|
|
347
|
+
key: "convertToCSV",
|
|
348
|
+
value: function convertToCSV(objArray) {
|
|
349
|
+
var array = _typeof(objArray) != 'object' ? JSON.parse(objArray) : objArray;
|
|
350
|
+
var str = '';
|
|
351
|
+
for (var i = 0; i < array.length; i++) {
|
|
352
|
+
var line = '';
|
|
353
|
+
for (var index in array[i]) {
|
|
354
|
+
if (line != '') line += ',';
|
|
355
|
+
line += array[i][index];
|
|
356
|
+
}
|
|
357
|
+
str += line + '\r\n';
|
|
358
|
+
}
|
|
359
|
+
return str;
|
|
360
|
+
}
|
|
361
|
+
}, {
|
|
362
|
+
key: "exportToCSV",
|
|
363
|
+
value: function exportToCSV() {
|
|
364
|
+
var headers = {};
|
|
365
|
+
// add columns in sheet array
|
|
366
|
+
var _iterator3 = _createForOfIteratorHelper(this.props.columns),
|
|
367
|
+
_step3;
|
|
368
|
+
try {
|
|
369
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
370
|
+
var _column2 = _step3.value;
|
|
371
|
+
headers[_column2.key] = '"' + _column2.text + '"';
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Filter records before export
|
|
375
|
+
} catch (err) {
|
|
376
|
+
_iterator3.e(err);
|
|
377
|
+
} finally {
|
|
378
|
+
_iterator3.f();
|
|
379
|
+
}
|
|
380
|
+
var filterRecords = this.props.records;
|
|
381
|
+
if (this.props.dynamic === false) {
|
|
382
|
+
var _records = this.sortRecords(),
|
|
383
|
+
filterValue = this.state.filter_value;
|
|
384
|
+
filterRecords = _records;
|
|
385
|
+
if (filterValue) {
|
|
386
|
+
filterRecords = this.filterData(_records);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
var records = [];
|
|
390
|
+
// add data rows in sheet array
|
|
391
|
+
for (var i in filterRecords) {
|
|
392
|
+
var record = filterRecords[i],
|
|
393
|
+
newRecord = {};
|
|
394
|
+
var _iterator4 = _createForOfIteratorHelper(this.props.columns),
|
|
395
|
+
_step4;
|
|
396
|
+
try {
|
|
397
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
398
|
+
var column = _step4.value;
|
|
399
|
+
if (column.cell && typeof column.cell === 'function') {
|
|
400
|
+
var cellData = _server["default"].renderToStaticMarkup(column.cell(record, i));
|
|
401
|
+
cellData = this.strip(cellData);
|
|
402
|
+
newRecord[column.key] = cellData;
|
|
403
|
+
} else if (record[column.key]) {
|
|
404
|
+
var colValue = record[column.key];
|
|
405
|
+
colValue = typeof colValue === 'string' ? colValue.replace(/"/g, '""') : colValue;
|
|
406
|
+
newRecord[column.key] = '"' + colValue + '"';
|
|
407
|
+
} else {
|
|
408
|
+
newRecord[column.key] = '';
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} catch (err) {
|
|
412
|
+
_iterator4.e(err);
|
|
413
|
+
} finally {
|
|
414
|
+
_iterator4.f();
|
|
415
|
+
}
|
|
416
|
+
records.push(newRecord);
|
|
417
|
+
}
|
|
418
|
+
if (headers) {
|
|
419
|
+
records.unshift(headers);
|
|
420
|
+
}
|
|
421
|
+
// Convert Object to JSON
|
|
422
|
+
var jsonObject = JSON.stringify(records);
|
|
423
|
+
var csv = this.convertToCSV(jsonObject);
|
|
424
|
+
var exportedFilename = this.config.filename + '.csv' || 'export.csv';
|
|
425
|
+
var blob = new Blob([csv], {
|
|
426
|
+
type: 'text/csv;charset=utf-8;'
|
|
427
|
+
});
|
|
428
|
+
if (navigator.msSaveBlob) {
|
|
429
|
+
// IE 10+
|
|
430
|
+
navigator.msSaveBlob(blob, exportedFilename);
|
|
431
|
+
} else {
|
|
432
|
+
var link = document.createElement('a');
|
|
433
|
+
if (link.download !== undefined) {
|
|
434
|
+
// feature detection
|
|
435
|
+
// Browsers that support HTML5 download attribute
|
|
436
|
+
var url = URL.createObjectURL(blob);
|
|
437
|
+
link.setAttribute('href', url);
|
|
438
|
+
link.setAttribute('download', exportedFilename);
|
|
439
|
+
link.style.visibility = 'hidden';
|
|
440
|
+
document.body.appendChild(link);
|
|
441
|
+
link.click();
|
|
442
|
+
link.remove();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}, {
|
|
447
|
+
key: "onChange",
|
|
448
|
+
value: function onChange() {
|
|
449
|
+
var tableData = {
|
|
450
|
+
filter_value: this.state.filter_value,
|
|
451
|
+
page_number: this.state.page_number,
|
|
452
|
+
page_size: this.state.page_size,
|
|
453
|
+
sort_order: this.state.sort
|
|
454
|
+
};
|
|
455
|
+
this.props.onChange(tableData);
|
|
456
|
+
}
|
|
457
|
+
}, {
|
|
458
|
+
key: "filterData",
|
|
459
|
+
value: function filterData(records) {
|
|
460
|
+
var _this6 = this;
|
|
461
|
+
var filterValue = this.state.filter_value;
|
|
462
|
+
return records.filter(function (record) {
|
|
463
|
+
var allow = false;
|
|
464
|
+
_lodash["default"].each(_this6.props.columns, function (column, key) {
|
|
465
|
+
if (record[column.key]) {
|
|
466
|
+
allow = _lodash["default"].includes(record[column.key].toString().toLowerCase(), filterValue.toString().toLowerCase()) ? true : allow;
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
return allow;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}, {
|
|
473
|
+
key: "sortRecords",
|
|
474
|
+
value: function sortRecords() {
|
|
475
|
+
var _this7 = this;
|
|
476
|
+
if (this.state.sort) {
|
|
477
|
+
return _lodash["default"].orderBy(this.props.records, function (o) {
|
|
478
|
+
var colVal = o[_this7.state.sort.column];
|
|
479
|
+
var typeofColVal = _typeof(colVal);
|
|
480
|
+
if (typeofColVal == 'string') {
|
|
481
|
+
if (isNaN(colVal)) {
|
|
482
|
+
return new String(colVal.toLowerCase());
|
|
483
|
+
} else {
|
|
484
|
+
return new Number(colVal);
|
|
485
|
+
}
|
|
486
|
+
} else if (typeofColVal == 'number') {
|
|
487
|
+
return new Number(colVal);
|
|
488
|
+
}
|
|
489
|
+
}, [this.state.sort.order]);
|
|
490
|
+
} else {
|
|
491
|
+
return this.props.records;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}, {
|
|
495
|
+
key: "render",
|
|
496
|
+
value: function render() {
|
|
497
|
+
var _this8 = this;
|
|
498
|
+
var filterRecords, totalRecords, pages, isFirst, isLast;
|
|
499
|
+
if (this.props.dynamic === false) {
|
|
500
|
+
var records = this.props.onSort ? this.props.onSort(this.state.sort.column, this.props.records, this.state.sort.order) : this.sortRecords(),
|
|
501
|
+
filterValue = this.state.filter_value;
|
|
502
|
+
filterRecords = records;
|
|
503
|
+
if (filterValue) {
|
|
504
|
+
filterRecords = this.filterData(records);
|
|
505
|
+
}
|
|
506
|
+
totalRecords = Array.isArray(filterRecords) ? filterRecords.length : 0;
|
|
507
|
+
pages = this.pages = this.numPages(totalRecords);
|
|
508
|
+
isFirst = this.isFirst();
|
|
509
|
+
isLast = this.isLast();
|
|
510
|
+
filterRecords = Array.isArray(filterRecords) ? this.paginate(filterRecords) : [];
|
|
511
|
+
} else {
|
|
512
|
+
filterRecords = this.props.records;
|
|
513
|
+
totalRecords = this.props.total_record;
|
|
514
|
+
pages = this.pages = this.numPages(totalRecords);
|
|
515
|
+
isFirst = this.isFirst();
|
|
516
|
+
isLast = this.isLast();
|
|
517
|
+
}
|
|
518
|
+
var startRecords = this.state.page_number * this.state.page_size - (this.state.page_size - 1);
|
|
519
|
+
var endRecords = this.state.page_size * this.state.page_number;
|
|
520
|
+
endRecords = endRecords > totalRecords ? totalRecords : endRecords;
|
|
521
|
+
var lengthMenuText = this.config.language.length_menu;
|
|
522
|
+
lengthMenuText = lengthMenuText.split('_MENU_');
|
|
523
|
+
var paginationInfo = this.config.language.info;
|
|
524
|
+
paginationInfo = paginationInfo.replace('_START_', this.state.page_number == 1 ? 1 : startRecords);
|
|
525
|
+
paginationInfo = paginationInfo.replace('_END_', endRecords);
|
|
526
|
+
paginationInfo = paginationInfo.replace('_TOTAL_', totalRecords);
|
|
527
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
528
|
+
className: "as-react-table",
|
|
529
|
+
id: this.props.id ? this.props.id + '-container' : '',
|
|
530
|
+
children: [this.config.show_filter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableHeader["default"], {
|
|
531
|
+
config: this.config,
|
|
532
|
+
id: this.props.id,
|
|
533
|
+
lengthMenuText: lengthMenuText,
|
|
534
|
+
recordLength: this.props.dynamic ? this.props.total_record : this.props.records.length,
|
|
535
|
+
filterRecords: this.filterRecords.bind(this),
|
|
536
|
+
changePageSize: this.changePageSize.bind(this),
|
|
537
|
+
exportToExcel: this.exportToExcel.bind(this),
|
|
538
|
+
exportToCSV: this.exportToCSV.bind(this),
|
|
539
|
+
exportToPDF: this.exportToPDF.bind(this),
|
|
540
|
+
extraButtons: this.props.extraButtons
|
|
541
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
542
|
+
className: "row table-body asrt-table-body",
|
|
543
|
+
style: _style2["default"].table_body,
|
|
544
|
+
id: this.props.id ? this.props.id + '-table-body' : '',
|
|
545
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
546
|
+
className: "col-md-12",
|
|
547
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("table", {
|
|
548
|
+
className: this.props.className,
|
|
549
|
+
id: this.props.id,
|
|
550
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("thead", {
|
|
551
|
+
className: this.props.tHeadClassName ? this.props.tHeadClassName : '',
|
|
552
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
553
|
+
children: this.props.columns.map(function (column, index) {
|
|
554
|
+
var classText = column.sortable ? 'sortable ' : '',
|
|
555
|
+
width = column.width ? column.width : '',
|
|
556
|
+
align = column.align ? column.align : '',
|
|
557
|
+
sortOrder = '',
|
|
558
|
+
columnStyle = {};
|
|
559
|
+
if (column.sortable && _this8.state.sort.column == column.key) {
|
|
560
|
+
sortOrder = _this8.state.sort.order;
|
|
561
|
+
classText += sortOrder ? ' ' + sortOrder : '';
|
|
562
|
+
columnStyle = sortOrder == 'asc' ? _style2["default"].sort_asc : _style2["default"].sort_desc;
|
|
563
|
+
}
|
|
564
|
+
classText += ' text-' + align;
|
|
565
|
+
if (column.TrOnlyClassName) classText += ' ' + column.TrOnlyClassName;
|
|
566
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
|
|
567
|
+
className: classText,
|
|
568
|
+
width: width,
|
|
569
|
+
style: columnStyle,
|
|
570
|
+
onClick: function onClick(event) {
|
|
571
|
+
return _this8.sortColumn(event, column, sortOrder);
|
|
572
|
+
},
|
|
573
|
+
children: column.text
|
|
574
|
+
}, column.key ? column.key : column.text);
|
|
575
|
+
})
|
|
576
|
+
})
|
|
577
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("tbody", {
|
|
578
|
+
children: this.props.loading === true ? /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
579
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
580
|
+
colSpan: this.props.columns.length,
|
|
581
|
+
className: "asrt-td-loading",
|
|
582
|
+
align: "center",
|
|
583
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
584
|
+
className: "asrt-loading-textwrap",
|
|
585
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
586
|
+
className: "asrt-loading-text",
|
|
587
|
+
children: this.config.language.loading_text
|
|
588
|
+
})
|
|
589
|
+
})
|
|
590
|
+
})
|
|
591
|
+
}) : filterRecords.length ? filterRecords.map(function (record, rowIndex) {
|
|
592
|
+
var _record$_this8$config;
|
|
593
|
+
rowIndex = _lodash["default"].indexOf(_this8.props.records, record);
|
|
594
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
595
|
+
onClick: function onClick(e) {
|
|
596
|
+
return _this8.props.onRowClicked(e, record, rowIndex);
|
|
597
|
+
},
|
|
598
|
+
children: _this8.props.columns.map(function (column, colIndex) {
|
|
599
|
+
if (column.cell && typeof column.cell === 'function') {
|
|
600
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
601
|
+
className: column.className,
|
|
602
|
+
children: column.cell(record, rowIndex)
|
|
603
|
+
}, column.key ? column.key : column.text);
|
|
604
|
+
} else if (record[column.key]) {
|
|
605
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
606
|
+
className: column.className,
|
|
607
|
+
children: record[column.key]
|
|
608
|
+
}, column.key ? column.key : column.text);
|
|
609
|
+
} else {
|
|
610
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
611
|
+
className: column.className
|
|
612
|
+
}, column.key ? column.key : column.text);
|
|
613
|
+
}
|
|
614
|
+
})
|
|
615
|
+
}, (_record$_this8$config = record[_this8.config.key_column]) !== null && _record$_this8$config !== void 0 ? _record$_this8$config : rowIndex);
|
|
616
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
617
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
618
|
+
colSpan: this.props.columns.length,
|
|
619
|
+
align: "center",
|
|
620
|
+
children: this.config.language.no_data_text
|
|
621
|
+
})
|
|
622
|
+
})
|
|
623
|
+
})]
|
|
624
|
+
})
|
|
625
|
+
})
|
|
626
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableFooter["default"], {
|
|
627
|
+
config: this.config,
|
|
628
|
+
id: this.props.id,
|
|
629
|
+
isFirst: isFirst,
|
|
630
|
+
isLast: isLast,
|
|
631
|
+
paginationInfo: paginationInfo,
|
|
632
|
+
pages: pages,
|
|
633
|
+
page_number: this.state.page_number,
|
|
634
|
+
is_temp_page: this.state.is_temp_page,
|
|
635
|
+
temp_page_number: this.state.temp_page_number,
|
|
636
|
+
firstPage: this.firstPage.bind(this),
|
|
637
|
+
lastPage: this.lastPage.bind(this),
|
|
638
|
+
previousPage: this.previousPage.bind(this),
|
|
639
|
+
nextPage: this.nextPage.bind(this),
|
|
640
|
+
goToPage: this.goToPage.bind(this),
|
|
641
|
+
changePageSize: this.changePageSize.bind(this),
|
|
642
|
+
onPageChange: this.onPageChange.bind(this),
|
|
643
|
+
onPageBlur: this.onPageBlur.bind(this)
|
|
644
|
+
})]
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
}]);
|
|
648
|
+
}(_react.Component);
|
|
649
|
+
/**
|
|
650
|
+
* Define component display name
|
|
651
|
+
*/
|
|
652
|
+
ReactDatatable.displayName = 'ReactDatatable';
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Define defaultProps for this component
|
|
656
|
+
*/
|
|
657
|
+
ReactDatatable.defaultProps = {
|
|
658
|
+
id: 'as-react-datatable',
|
|
659
|
+
className: 'table table-bordered table-striped',
|
|
660
|
+
columns: [],
|
|
661
|
+
config: {
|
|
662
|
+
button: {
|
|
663
|
+
excel: false,
|
|
664
|
+
print: false,
|
|
665
|
+
csv: false
|
|
666
|
+
},
|
|
667
|
+
filename: 'table',
|
|
668
|
+
key_column: 'id',
|
|
669
|
+
language: {
|
|
670
|
+
length_menu: 'Show _MENU_ records per page',
|
|
671
|
+
filter: 'Search in records...',
|
|
672
|
+
info: 'Showing _START_ to _END_ of _TOTAL_ entries',
|
|
673
|
+
pagination: {
|
|
674
|
+
first: 'First',
|
|
675
|
+
previous: 'Previous',
|
|
676
|
+
next: 'Next',
|
|
677
|
+
last: 'Last'
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
length_menu: [10, 25, 50, 75, 100],
|
|
681
|
+
no_data_text: 'No rows found',
|
|
682
|
+
page_size: 10,
|
|
683
|
+
sort: {
|
|
684
|
+
column: 'test',
|
|
685
|
+
order: 'asc'
|
|
686
|
+
},
|
|
687
|
+
show_length_menu: true,
|
|
688
|
+
show_filter: true,
|
|
689
|
+
show_pagination: true,
|
|
690
|
+
show_info: true,
|
|
691
|
+
show_first: true,
|
|
692
|
+
show_last: true
|
|
693
|
+
},
|
|
694
|
+
dynamic: false,
|
|
695
|
+
records: [],
|
|
696
|
+
total_record: 0,
|
|
697
|
+
onChange: function onChange() {},
|
|
698
|
+
onPageChange: function onPageChange() {},
|
|
699
|
+
onRowClicked: function onRowClicked() {}
|
|
700
|
+
};
|
|
701
|
+
var _default = exports["default"] = ReactDatatable;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _upArrow = _interopRequireDefault(require("../assets/img/up-arrow.png"));
|
|
8
|
+
var _downArrow = _interopRequireDefault(require("../assets/img/down-arrow.png"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
var _default = exports["default"] = {
|
|
11
|
+
table_body: {
|
|
12
|
+
marginTop: '12px'
|
|
13
|
+
},
|
|
14
|
+
table_size: {
|
|
15
|
+
background: 'none',
|
|
16
|
+
border: 'none',
|
|
17
|
+
padding: 0
|
|
18
|
+
},
|
|
19
|
+
table_size_dropdown: {
|
|
20
|
+
width: '70px',
|
|
21
|
+
flex: 'none',
|
|
22
|
+
margin: '0px 10px',
|
|
23
|
+
display: 'inline-block',
|
|
24
|
+
"float": 'none'
|
|
25
|
+
},
|
|
26
|
+
table_filter: {
|
|
27
|
+
display: 'inline-block',
|
|
28
|
+
verticalAlign: 'top',
|
|
29
|
+
marginRight: '5px',
|
|
30
|
+
width: '250px'
|
|
31
|
+
},
|
|
32
|
+
table_tool: {
|
|
33
|
+
display: 'inline-block',
|
|
34
|
+
verticalAlign: 'top'
|
|
35
|
+
},
|
|
36
|
+
table_tool_btn: {
|
|
37
|
+
marginRight: '5px'
|
|
38
|
+
},
|
|
39
|
+
sort_asc: {
|
|
40
|
+
backgroundImage: "url(".concat(_upArrow["default"], ")")
|
|
41
|
+
},
|
|
42
|
+
sort_desc: {
|
|
43
|
+
backgroundImage: "url(".concat(_downArrow["default"], ")")
|
|
44
|
+
}
|
|
45
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "CardFilter", {
|
|
|
9
9
|
return _CardFilter["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "DataGridView", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _DataGridView["default"];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "InputCheck", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function get() {
|
|
@@ -17,4 +23,5 @@ Object.defineProperty(exports, "InputCheck", {
|
|
|
17
23
|
});
|
|
18
24
|
var _CardFilter = _interopRequireDefault(require("./CardFilter"));
|
|
19
25
|
var _InputCheck = _interopRequireDefault(require("./InputCheck"));
|
|
26
|
+
var _DataGridView = _interopRequireDefault(require("./DataGridView"));
|
|
20
27
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|