jb-grid 0.4.1 → 0.5.0

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 (117) hide show
  1. package/README.md +138 -11
  2. package/package.json +5 -8
  3. package/react/README.md +207 -202
  4. package/react/dist/Content.d.ts +1 -2
  5. package/react/dist/Footer.d.ts +1 -2
  6. package/react/dist/Header.d.ts +3 -16
  7. package/react/dist/JBGrid.cjs.js +3631 -1
  8. package/react/dist/JBGrid.cjs.js.map +1 -1
  9. package/react/dist/JBGrid.d.ts +288 -26
  10. package/react/dist/JBGrid.js +3624 -1
  11. package/react/dist/JBGrid.js.map +1 -1
  12. package/react/dist/JBGrid.umd.js +3641 -1
  13. package/react/dist/JBGrid.umd.js.map +1 -1
  14. package/react/dist/JBGridData.d.ts +1 -5
  15. package/react/dist/JBGridViewModel.d.ts +28 -25
  16. package/react/dist/types.d.ts +17 -49
  17. package/react/lib/Components/Cell.tsx +17 -15
  18. package/react/lib/Components/ColumnHeader.tsx +44 -0
  19. package/react/lib/Components/ExpandToggle.tsx +14 -10
  20. package/react/lib/Components/FullscreenIcon.tsx +28 -0
  21. package/react/lib/Components/JBLoading.tsx +5 -4
  22. package/react/lib/Components/Pagination.tsx +1 -1
  23. package/react/lib/Components/PaginationInfo.tsx +71 -0
  24. package/react/lib/Components/RefreshIcon.tsx +11 -0
  25. package/react/lib/Components/Row.tsx +17 -15
  26. package/react/lib/Components/TableHeader.tsx +21 -0
  27. package/react/lib/Components/blob-loading.css +27 -23
  28. package/react/lib/Components/cell.css +7 -7
  29. package/react/lib/Components/content-error/ContentError.tsx +19 -16
  30. package/react/lib/Components/content-error/content-error.css +5 -11
  31. package/react/lib/Components/module-declaration.ts +61 -13
  32. package/react/lib/Content.tsx +23 -47
  33. package/react/lib/Footer.tsx +52 -79
  34. package/react/lib/Header.tsx +11 -24
  35. package/react/lib/JBGrid.tsx +129 -70
  36. package/react/lib/JBGridViewModel.ts +189 -452
  37. package/react/lib/footer.css +25 -55
  38. package/react/lib/header.css +20 -20
  39. package/react/lib/jb-grid.css +69 -55
  40. package/react/lib/types.ts +32 -129
  41. package/react/lib/variables.css +6 -0
  42. package/react/package.json +14 -10
  43. package/react/tsconfig.json +5 -4
  44. package/web-component/dist/index.cjs.js +559 -1
  45. package/web-component/dist/index.cjs.js.br +0 -0
  46. package/web-component/dist/index.cjs.js.gz +0 -0
  47. package/web-component/dist/index.cjs.js.map +1 -1
  48. package/web-component/dist/index.d.ts +161 -4
  49. package/web-component/dist/index.d.ts.map +1 -1
  50. package/web-component/dist/index.js +561 -1
  51. package/web-component/dist/index.js.br +0 -0
  52. package/web-component/dist/index.js.gz +0 -0
  53. package/web-component/dist/index.js.map +1 -1
  54. package/web-component/dist/index.umd.js +567 -1
  55. package/web-component/dist/index.umd.js.br +0 -0
  56. package/web-component/dist/index.umd.js.gz +0 -0
  57. package/web-component/dist/index.umd.js.map +1 -1
  58. package/web-component/dist/row/row.d.ts.map +1 -1
  59. package/web-component/dist/row/types.d.ts +3 -5
  60. package/web-component/dist/row/types.d.ts.map +1 -1
  61. package/web-component/dist/row/utils.d.ts +1 -2
  62. package/web-component/dist/row/utils.d.ts.map +1 -1
  63. package/web-component/dist/table-header/render.d.ts +2 -0
  64. package/web-component/dist/table-header/render.d.ts.map +1 -0
  65. package/web-component/dist/table-header/table-header.d.ts +9 -0
  66. package/web-component/dist/table-header/table-header.d.ts.map +1 -0
  67. package/web-component/dist/table-header/types.d.ts +4 -0
  68. package/web-component/dist/table-header/types.d.ts.map +1 -0
  69. package/web-component/dist/types.d.ts +6 -0
  70. package/web-component/dist/types.d.ts.map +1 -0
  71. package/web-component/dist/utils.d.ts +8 -0
  72. package/web-component/dist/utils.d.ts.map +1 -0
  73. package/web-component/lib/cell/cell.ts +10 -5
  74. package/web-component/lib/cell/style.css +2 -1
  75. package/web-component/lib/column-header/column-header.ts +117 -0
  76. package/web-component/lib/column-header/render.ts +14 -0
  77. package/web-component/lib/column-header/style.css +60 -0
  78. package/web-component/lib/column-header/types.ts +10 -0
  79. package/web-component/lib/fullscreen-icon/fullscreen-icon.ts +72 -0
  80. package/web-component/lib/fullscreen-icon/render.ts +23 -0
  81. package/web-component/lib/fullscreen-icon/style.css +44 -0
  82. package/web-component/lib/fullscreen-icon/types.ts +1 -0
  83. package/web-component/lib/i18n.ts +38 -0
  84. package/web-component/lib/index.ts +9 -4
  85. package/web-component/lib/pagination/README.md +4 -0
  86. package/web-component/lib/pagination/pagination.ts +25 -15
  87. package/web-component/lib/pagination/render.ts +13 -10
  88. package/web-component/lib/pagination/style.css +43 -31
  89. package/web-component/lib/pagination/types.ts +1 -1
  90. package/web-component/lib/pagination/variables.css +10 -0
  91. package/web-component/lib/pagination-info/pagination-info.ts +191 -0
  92. package/web-component/lib/pagination-info/render.ts +16 -0
  93. package/web-component/lib/pagination-info/style.css +47 -0
  94. package/web-component/lib/pagination-info/types.ts +12 -0
  95. package/web-component/lib/refresh-icon/refresh-icon.ts +79 -0
  96. package/web-component/lib/refresh-icon/render.ts +10 -0
  97. package/web-component/lib/refresh-icon/style.css +21 -0
  98. package/web-component/lib/row/render.ts +3 -3
  99. package/web-component/lib/row/row.ts +29 -15
  100. package/web-component/lib/row/style.css +30 -30
  101. package/web-component/lib/row/types.ts +7 -8
  102. package/web-component/lib/row/utils.ts +1 -40
  103. package/web-component/lib/row/variables.css +13 -0
  104. package/web-component/lib/table-header/render.ts +9 -0
  105. package/web-component/lib/table-header/style.css +29 -0
  106. package/web-component/lib/table-header/table-header.ts +50 -0
  107. package/web-component/lib/table-header/types.ts +4 -0
  108. package/web-component/lib/toggle/expand-toggle.ts +17 -13
  109. package/web-component/lib/toggle/render.ts +18 -13
  110. package/web-component/lib/toggle/style.css +18 -5
  111. package/web-component/lib/types.ts +6 -0
  112. package/web-component/lib/utils.ts +46 -0
  113. package/react/lib/JBGridBridgeExample.js +0 -90
  114. package/react/lib/JBGridData.ts +0 -51
  115. package/react/lib/global.d.ts +0 -15
  116. package/web-component/lib/global.d.ts +0 -15
  117. package/web-component/tsconfig.json +0 -17
package/README.md CHANGED
@@ -40,9 +40,26 @@ For the standalone pagination API and CSS variables, see [jb-pagination README](
40
40
 
41
41
  ### jb-pagination CSS variables
42
42
 
43
- | CSS variable name | description |
44
- | --- | --- |
45
- | --jb-pagination-index-width | Width of each page index button. |
43
+ | CSS variable name | description |
44
+ | --- | --- |
45
+ | --jb-pagination-arrow-button-fill-color | Fill color of pagination arrow buttons. |
46
+ | --jb-pagination-arrow-button-fill-color-disabled | Fill color of disabled pagination arrow buttons. |
47
+ | --jb-pagination-index-width | Width of each page index button. |
48
+ | --jb-pagination-page-index-color | Color of page index buttons. |
49
+ | --jb-pagination-page-index-color-current | Color of the current page index button. |
50
+
51
+ ### jb-row CSS variables
52
+
53
+ | CSS variable name | description |
54
+ | --- | --- |
55
+ | --jb-row-bg-color | Row background color. |
56
+ | --jb-row-bg-color-even | Even row background color. |
57
+ | --jb-row-bg-color-even-tablet | Even row background color in tablet layout. |
58
+ | --jb-row-border-radius | Row border radius in tablet layout. |
59
+ | --jb-row-expand-border-color | Expand panel bottom border color. |
60
+ | --jb-row-expand-padding-block | Expand panel block padding. |
61
+ | --jb-row-expand-padding-inline | Expand panel inline padding. |
62
+ | --jb-row-shadow-color | Row shadow color in tablet layout. |
46
63
 
47
64
  ## Row & Cells
48
65
  `jb-row` is a row web-component that imply a grid template based on given config to below cells. it also accept expand row that you can open and close it.
@@ -64,7 +81,7 @@ to set column size of the row you can pass a config that tell each column size.
64
81
  ```js
65
82
  document.querySelector(""jb-row).rowTemplate = [
66
83
  {name:"id",size:"1fr"},
67
- {name:"name",size:"400px"},
84
+ {name:"name",size:"25rem"},
68
85
  {name:"age",size:200},
69
86
  {name:"operation",size:20%},
70
87
  ]
@@ -91,11 +108,121 @@ document.querySelector(`jb-row`).isOpen = true;
91
108
  document.querySelector(`jb-row`).isOpen = false;
92
109
  ```
93
110
 
94
- ### Ellipses Cell
95
-
96
- if your cell content is a long text need to get ellipses on overflow add `ellipsis` attribute to the `jb-cell` and `ellipsis="max line"` for multiline
111
+ ### Ellipses Cell
112
+
113
+ Cells clip horizontal overflow to stay inside their grid column. If long text should show an ellipsis, add the `ellipsis` attribute to `jb-cell`; use `ellipsis="max line"` for multiline truncation.
97
114
  ```html
98
- <jb-cell ellipsis>Put Long Text Here</jb-cell>
99
- <!-- Limited Browser Support for Multiline -->
100
- <jb-cell ellipsis="3">Put Long Text Here</jb-cell>
101
- ```
115
+ <jb-cell ellipsis>Put Long Text Here</jb-cell>
116
+ <!-- Limited Browser Support for Multiline -->
117
+ <jb-cell ellipsis="3">Put Long Text Here</jb-cell>
118
+ ```
119
+
120
+ ## Table Header
121
+
122
+ `jb-table-header` is a grid header wrapper for `jb-col-header` cells. Set `headerTemplate` to the same column template shape used by `jb-row`.
123
+
124
+ ```html
125
+ <jb-table-header>
126
+ <jb-col-header name="id">
127
+ <span slot="title">ID</span>
128
+ </jb-col-header>
129
+ <jb-col-header name="name" sortable>
130
+ <span slot="title">Name</span>
131
+ </jb-col-header>
132
+ </jb-table-header>
133
+ ```
134
+
135
+ ```js
136
+ import 'jb-grid';
137
+
138
+ document.querySelector('jb-table-header').headerTemplate = [
139
+ { name: 'id', size: '5rem' },
140
+ { name: 'name', size: '1fr' },
141
+ ];
142
+ ```
143
+
144
+ ### jb-table-header API
145
+
146
+ | name | type | description |
147
+ | --- | --- | --- |
148
+ | `headerTemplate` | property | Column template config for the header grid. |
149
+
150
+ ### jb-col-header API
151
+
152
+ | name | type | description |
153
+ | --- | --- | --- |
154
+ | `name` | attribute/property | Column name. It is used as the grid-area name. |
155
+ | `sortable` | attribute/property | Enables click sorting for this column. |
156
+ | `sort` | attribute/property | Current sort direction. Accepts `asc`, `desc`, or no value. |
157
+ | `sort` | event | Fired when a sortable header is clicked. Event detail is `{ name, sort }`. |
158
+ | `title` | slot | Header caption content. |
159
+
160
+ ```js
161
+ document.querySelector('jb-col-header').addEventListener('sort', (event) => {
162
+ console.log(event.detail.name, event.detail.sort);
163
+ });
164
+ ```
165
+
166
+ ## Pagination Info
167
+
168
+ `jb-pagination-info` shows page-size selection and the current item range.
169
+
170
+ ```html
171
+ <jb-pagination-info></jb-pagination-info>
172
+ ```
173
+
174
+ ```js
175
+ const paginationInfo = document.querySelector('jb-pagination-info');
176
+
177
+ paginationInfo.pageSize = 20;
178
+ paginationInfo.pageSizes = [10, 20, 50, 100];
179
+ paginationInfo.startItemIndex = 1;
180
+ paginationInfo.endItemIndex = 20;
181
+ paginationInfo.totalItemsCount = 124;
182
+ paginationInfo.pageItemCountTitle = 'Items per page';
183
+ paginationInfo.fromLabel = 'of';
184
+ paginationInfo.currentAvailableItemTitle = 'Available items';
185
+ paginationInfo.showPersianNumber = false;
186
+
187
+ paginationInfo.addEventListener('page-size-change', (event) => {
188
+ console.log(event.detail.pageSize);
189
+ });
190
+ ```
191
+
192
+ ### jb-pagination-info API
193
+
194
+ | name | type | description |
195
+ | --- | --- | --- |
196
+ | `pageSize` | property | Current selected page size. |
197
+ | `pageSizes` | property | Available page-size options. Default is `[20, 30, 50, 100]`. |
198
+ | `startItemIndex` | property | First visible item index. |
199
+ | `endItemIndex` | property | Last visible item index. |
200
+ | `totalItemsCount` | property | Total item count. |
201
+ | `pageItemCountTitle` | property | Tooltip text for the page-size section. |
202
+ | `fromLabel` | property | Label rendered before the total count. |
203
+ | `currentAvailableItemTitle` | property | Tooltip text for the total count. |
204
+ | `showPersianNumber` | property | Converts displayed numbers to Persian digits when `true`. |
205
+ | `page-size-change` | event | Fired when the selected page size changes. Event detail is `{ pageSize }`. |
206
+
207
+ ## Utility Icons
208
+
209
+ `jb-refresh-icon` and `jb-fullscreen-icon` are standalone icons used by the grid controls.
210
+
211
+ ```html
212
+ <jb-refresh-icon></jb-refresh-icon>
213
+ <jb-fullscreen-icon state="enter"></jb-fullscreen-icon>
214
+ ```
215
+
216
+ ### jb-refresh-icon API
217
+
218
+ | name | type | description |
219
+ | --- | --- | --- |
220
+ | `play()` | method | Starts the refresh rotation animation. |
221
+ | `pause()` | method | Pauses the refresh rotation animation. |
222
+ | `stop()` | method | Stops the animation after the current rotation finishes. |
223
+
224
+ ### jb-fullscreen-icon API
225
+
226
+ | name | type | description |
227
+ | --- | --- | --- |
228
+ | `state` | attribute/property | Icon state. Accepts `enter` or `exit`. |
package/package.json CHANGED
@@ -14,17 +14,15 @@
14
14
  "web component",
15
15
  "react component"
16
16
  ],
17
- "version": "0.4.1",
17
+ "version": "0.5.0",
18
18
  "bugs": "https://github.com/javadbat/jb-grid/issues",
19
19
  "license": "MIT",
20
20
  "files": [
21
21
  "LICENSE",
22
22
  "README.md",
23
- "lib/",
24
- "dist/",
25
23
  "react/",
26
- "web-component/",
27
- "web-component/dist",
24
+ "web-component/lib/",
25
+ "web-component/dist/",
28
26
  "react/dist/"
29
27
  ],
30
28
  "main": "index.js",
@@ -34,9 +32,8 @@
34
32
  "url": "git@github.com:javadbat/jb-grid.git"
35
33
  },
36
34
  "dependencies": {
37
- "jb-core":">=0.27.2",
38
- "mobx":">=6.0.0",
39
- "mobx-react":">=7.0.0",
35
+ "jb-button":">=3.10.0",
36
+ "jb-core":">=0.30.0",
40
37
  "jb-searchbar":">=3.0.2"
41
38
  }
42
39
  }
package/react/README.md CHANGED
@@ -1,206 +1,211 @@
1
- # jb-grid React component
2
-
3
- [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/jb-grid)
4
- [![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/javadbat/jb-grid/main/LICENSE)
5
- [![NPM Version](https://img.shields.io/npm/v/jb-grid-react)](https://www.npmjs.com/package/jb-grid-react)
6
- ![GitHub Created At](https://img.shields.io/github/created-at/javadbat/jb-grid)
7
-
8
- react mobx table grid with pagination, filtering and sorting functionality.
9
-
10
- - responsive
11
- - mobx ready
12
- - easy filter implementation (customizable)
13
- - customizable column templates
14
- - flexible column size
15
- - support for server side data fetching
16
-
17
- ## instructions
18
-
19
- ### install the package
20
-
21
- ```sh
22
- npm i jb-grid
23
- ```
24
-
25
- ### import and use in your component
26
- ```JSX
27
- import {Cell, Row, JBGrid} from 'jb-grid/react';
28
- //this file is a class that implement `JBGridBridgeClassInterface` interface to translate your server data to jb-grid data interface see Bridge section for more detail
29
- import {JBGridBridge} from './my-bridge';
30
- // grid config that impl JBGridConfig type see config section for more detail
31
- import {yourConfig} from './your-grid-config-file';
32
- //jb-search-bar config so you can filter your data
33
- import {filterConfig} from './my-filter-config';
34
-
35
- <JBGrid config={yourConfig} bridge={JBGridBridge} title="user list" searchbarConfig={vm.filterConfig}></JBGrid>
36
- ```
37
-
38
- ### config
39
-
40
- config is unique for each data table you want to show and contains information about columns,filters,sort,initData,...
41
- you can create your own config from scratch using Mobx class Stores that implements `JBGridConfigInterface` or just create instance of `JBGridData` and start to config it's fields based on your need.
42
-
43
- ```js
44
- import { JBGridData } from "jb-grid/react";
45
-
46
- const yourConfig = new JBGridData();
47
- ```
48
- or in typescript: (in javascript you don't need to implements from `JBGridConfigInterface` but you have to check every detail manually to avoid errors)
49
- ```ts
50
- import {JBGridConfigInterface} from "jb-grid/types"
51
-
52
- class yourConfigClass implements JBGridConfigInterface{
53
- //put your config here. for sample code see /lib/JBGridData in package files
54
- }
55
- export const yourConfig = new yourConfigClass();
56
- ```
57
- you can config columns of table like this:
58
-
59
- ```js
60
- yourConfig.table.columns = [
61
- {
62
- //uniq identifier of column
63
- id: 1,
64
- //will be used as a key in sort object when sorting by column
65
- name: 'name',
66
- //showed in column header
67
- title: 'نام',
68
- //let us sort column default is false
69
- sortable: true,
70
- },
71
- {
72
- id: 2,
73
- name: 'age',
74
- title: 'سن',
75
- sortable: false,
76
- //if you don't set width , it will be '1fr' mean it get 1 share of width from free space
77
- width: '1fr'
78
- },
79
- {
80
- id: 3,
81
- name: 'expand',
82
- title: 'باز کردن',
83
- sortable: false,
84
- //you can set px,em, auto, fr , % , ... in here
85
- width: '200px'
86
- }
87
- ];
88
-
89
- ```
90
- to config backend service call config you can set `` like this:
91
- ```js
92
- // your api endpoint
93
- yourConfig.data.requestParams.url = "http://localhost:3000/grid/user-list",
94
- //endpoint http method
95
- yourConfig.data.requestParams.method = "POST";
96
- // you can set any custom parameter your backend needs here. for example if you using grpc or graphql you can set any config they need
97
- yourConfig.data.requestParams.custom1 = {aa:""};
98
- yourConfig.data.requestParams.foo = "x";
99
- ```
100
- ### i18n
101
- you can pass a i18n config to set a text, number display and other localization config to jb-grid
102
- ```tsx
103
- const i18nMessages:JBGridI18nMessage = {
104
- EnterPageNumberMessage:"شماره صفحه ای که میخواهید وارد آن شوید را وارد کنید",
105
- serverErrorText:"متاسفانه در هنگام بارگذاری اطلاعات خطایی رخ داده است",
106
- serverErrorTitle:"すみません",
107
- serverErrorRefreshButtonTitle:"تلاش مجدد",
108
- currentAvailableItem:"تعداد کل ایتم های موجود",
109
- pageItemCount:"تعداد آیتم در هر صفحه",
110
- from:"از"
111
- };
112
- export const i18n:JBGridI18nConfig = {
113
- messages: i18nMessages,
114
- showPersianNumber:false
115
- };
116
- <JBGrid i18n={i18n}></JBGrid>
117
-
118
- ```
119
- ### actions
120
-
121
- there is some actions you may want to call inside a grid for example you need to refresh data by code after some entity insert/update or fullscreen grid by code. for doing so you just have to call `actionDispatchers` methods in your grid config after initialization process (after render of jb-grid finish grid will automatically extend your config and add this methods).
122
- ```typescript
123
- //action dispatcher type in typescript:
124
- type ActionDispatchers = Readonly<{
125
- refreshData: () => Promise<void>,
126
- fullScreenGrid: () => void,
127
- exitFullScreenGrid: () => void
128
- }>
129
- // the call function:
130
- yourConfig.actionDispatchers.refreshData();
131
- //
132
- ```
133
-
134
- ### bridge
135
-
136
- bridge is a js/ts class, responsible for converting jb-grid standard data to your back-end standard data and reverse.
137
- jb-grid doesn't send request by it self, instead it ask bridge to send request & and receive data. so you have freedom to use whatever standard and technology you may see fit.
138
- the reason that we separate config & bridge is most of the time all tables of your project use same request and response data structure so you don't need to repeat yourself. you code 1 bridge for all of project and config each list for endpoints url ,...
139
-
140
- ### filter
141
-
142
- ### show list
143
-
144
- ### custom error page
145
-
146
- if you want to show customized error page instead of default one use `contentError` prop
147
- ```jsx
148
- <JBGrid contentError={<CustomErrorComponent />}></JBGrid>
149
- ```
150
-
151
- ### full-screen grid
152
-
153
- jb-grid has a fullscreenable feature and you can activate that by set `isFullscreen={value:bool}` for example
154
-
155
- ```jsx
156
- const [isFullscreen,setIsFullscreen] = useState(false);
157
- <JBGrid isFullscreen={isFullscreen} onFullscreenChange={(newValue)=>setIsFullscreen(newValue)}></JBGrid>
158
-
159
- ```
160
- ### expandable row
161
- you can add expandable row so user can expand row to see more info about a row in detail
162
-
163
- ```jsx
164
- <JBGrid config={jbGridConfig} bridge={JBGridBridge} title="general list" searchbarConfig={filterConfig}>
165
- {
166
- jbGridConfig.data.data.map(
167
- (item) => {
168
- return (
169
- <React.Fragment key={item.id}>
170
- <Row>
171
- <Cell>{item.name}</Cell>
172
- <Cell>{item.age}</Cell>
173
- <Cell><button onClick={()=>{item.jbGridDetail.isExpanded = !item.jbGridDetail.isExpanded;}}>detail</button></Cell>
174
- </Row>
175
- <ExpandRow show={item.jbGridDetail.isExpanded}>
176
- <YourExpandedData></YourExpandedData>
177
- </ExpandRow>
178
- </React.Fragment>
179
-
180
- );
181
- }
182
- )
183
- }
184
- </JBGrid>
185
-
186
- ```
187
-
188
- ## make it mobile friendly
189
-
190
- jb-grid by default is mobile friendly but when it turns to mobile view it show row as cards. this cards show the table fields in themselves but without any label. to show label of columns beside the cell in mobile just add `label` property to each cell like this:
191
- ```jsx
192
- <Row>
193
- <Cell label="name:">{item.name}</Cell>
194
- <Cell label="age:">{item.age}</Cell>
195
- <Cell label="operations:"><button onClick={()=>{item.jbGridDetail.isExpanded = !item.jbGridDetail.isExpanded;}}>detail</button></Cell>
196
- </Row>
197
- ```
198
-
1
+ # jb-grid React component
2
+
3
+ [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/jb-grid)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/javadbat/jb-grid/main/LICENSE)
5
+ [![NPM Version](https://img.shields.io/npm/v/jb-grid-react)](https://www.npmjs.com/package/jb-grid-react)
6
+ ![GitHub Created At](https://img.shields.io/github/created-at/javadbat/jb-grid)
7
+
8
+ react table grid with pagination, filtering and sorting functionality.
9
+
10
+ - responsive
11
+ - React state ready
12
+ - easy filter implementation (customizable)
13
+ - customizable column templates
14
+ - flexible column size
15
+ - stateless data, pagination, loading, and error handling
16
+
17
+ ## instructions
18
+
19
+ ### install the package
20
+
21
+ ```sh
22
+ npm i jb-grid
23
+ ```
24
+
25
+ ### import and use in your component
26
+ ```JSX
27
+ import {JBCell, JBRow, JBGrid} from 'jb-grid/react';
28
+ import {Searchbar} from './Searchbar';
29
+
30
+ <JBGrid
31
+ data={data}
32
+ pageIndex={pageIndex}
33
+ pageSize={pageSize}
34
+ totalItemsCount={totalItemsCount}
35
+ title="user list"
36
+ searchbarComponent={<Searchbar />}
37
+ onPageIndexChange={setPageIndex}
38
+ onPageSizeChange={setPageSize}
39
+ onRefresh={refreshData}
40
+ ></JBGrid>
41
+ ```
42
+
43
+ ### state
44
+
45
+ `JBGrid` is stateless. Keep data, pagination, loading, error, filtering, sorting, columns, and row expansion in your own component/store and pass the current values to the grid.
46
+
47
+ ```tsx
48
+ <JBGrid
49
+ data={data}
50
+ pageIndex={pageIndex}
51
+ pageSize={pageSize}
52
+ totalItemsCount={totalItemsCount}
53
+ totalPages={totalPages}
54
+ isLoading={isLoading}
55
+ isErrorOccurred={isErrorOccurred}
56
+ onPageIndexChange={(newPageIndex) => setPageIndex(newPageIndex)}
57
+ onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
58
+ onRefresh={() => loadData()}
59
+ title="user list"
60
+ />
61
+ ```
62
+
63
+ ### table header and rows
64
+
65
+ The grid does not own column definitions. If you need a table header, render it yourself with `tableHeader`. Pass row layout directly to `JBRow`.
66
+
67
+ ```ts
68
+ const rowTemplate = [
69
+ { name: "name", size: "1fr" },
70
+ { name: "age", size: "6.25rem" },
71
+ { name: "operation", size: "10rem" }
72
+ ];
73
+ ```
74
+ ```tsx
75
+ <JBTableHeader headerTemplate={rowTemplate}>
76
+ <JBColumnHeader name="id">ID</JBColumnHeader>
77
+ <JBColumnHeader name="name" sortable>Name</JBColumnHeader>
78
+ <JBColumnHeader name="family" sortable>Family</JBColumnHeader>
79
+ <JBColumnHeader name="age">Age</JBColumnHeader>
80
+ </JBTableHeader>
81
+ ```
82
+ ```tsx
83
+ <JBGrid
84
+ tableHeader={<YourTableHeader />}
85
+ data={data}
86
+ pageIndex={pageIndex}
87
+ pageSize={pageSize}
88
+ totalItemsCount={totalItemsCount}
89
+ title="user list"
90
+ >
91
+ {(data) => data.map((item) => (
92
+ <JBRow key={item.id} rowTemplate={rowTemplate}>
93
+ <JBCell name="name" label="name:">{item.name}</JBCell>
94
+ <JBCell name="age" label="age:">{item.age}</JBCell>
95
+ <JBCell name="operation" label="operations:"><button>detail</button></JBCell>
96
+ </JBRow>
97
+ ))}
98
+ </JBGrid>
99
+ ```
100
+
101
+ ### i18n
102
+ you can pass a i18n config to set a text, number display and other localization config to jb-grid
103
+ ```tsx
104
+ const i18nMessages:JBGridI18nMessage = {
105
+ EnterPageNumberMessage:"شماره صفحه ای که میخواهید وارد آن شوید را وارد کنید",
106
+ serverErrorText:"متاسفانه در هنگام بارگذاری اطلاعات خطایی رخ داده است",
107
+ serverErrorTitle:"すみません",
108
+ serverErrorRefreshButtonTitle:"تلاش مجدد",
109
+ currentAvailableItem:"تعداد کل ایتم های موجود",
110
+ pageItemCount:"تعداد آیتم در هر صفحه",
111
+ from:"از"
112
+ };
113
+ export const i18n:JBGridI18nConfig = {
114
+ messages: i18nMessages,
115
+ showPersianNumber:false
116
+ };
117
+ <JBGrid i18n={i18n} data={data} pageIndex={pageIndex} pageSize={pageSize} totalItemsCount={totalItemsCount}></JBGrid>
118
+
119
+ ```
120
+
121
+ ### filter
122
+
123
+ ### show list
124
+
125
+ ### custom error page
126
+
127
+ if you want to show customized error page instead of default one use `contentError` prop
128
+ ```jsx
129
+ <JBGrid {...gridProps} contentError={<CustomErrorComponent />} isErrorOccurred={isErrorOccurred}></JBGrid>
130
+ ```
131
+
132
+ ### full-screen grid
133
+
134
+ jb-grid has a fullscreenable feature and you can activate that by set `isFullscreen={value:bool}` for example
135
+
136
+ ```jsx
137
+ const [isFullscreen,setIsFullscreen] = useState(false);
138
+ <JBGrid {...gridProps} isFullscreen={isFullscreen} onFullscreen={()=>setIsFullscreen(true)} onExitFullscreen={()=>setIsFullscreen(false)}></JBGrid>
139
+
140
+ ```
141
+ ### expandable row
142
+ you can add expandable row so user can expand row to see more info about a row in detail
143
+
144
+ ```jsx
145
+ <JBGrid data={data} pageIndex={pageIndex} pageSize={pageSize} totalItemsCount={totalItemsCount} title="general list" searchbarComponent={<Searchbar />}>
146
+ {
147
+ (data) => data.map(
148
+ (item) => {
149
+ return (
150
+ <React.Fragment key={item.id}>
151
+ <JBRow isOpen={expandedRowIds.has(item.id)}>
152
+ <JBCell name="name">{item.name}</JBCell>
153
+ <JBCell name="age">{item.age}</JBCell>
154
+ <JBCell name="operation"><button onClick={()=>toggleRowExpanded(item.id)}>detail</button></JBCell>
155
+ <div slot="expand">
156
+ <YourExpandedData></YourExpandedData>
157
+ </div>
158
+ </JBRow>
159
+ </React.Fragment>
160
+
161
+ );
162
+ }
163
+ )
164
+ }
165
+ </JBGrid>
166
+
167
+ ```
168
+
169
+ ## make it mobile friendly
170
+
171
+ jb-grid by default is mobile friendly but when it turns to mobile view it show row as cards. this cards show the table fields in themselves but without any label. to show label of columns beside the cell in mobile just add `label` property to each cell like this:
172
+ ```jsx
173
+ <JBRow>
174
+ <JBCell name="name" label="name:">{item.name}</JBCell>
175
+ <JBCell name="age" label="age:">{item.age}</JBCell>
176
+ <JBCell name="operation" label="operations:"><button onClick={()=>toggleRowExpanded(item.id)}>detail</button></JBCell>
177
+ </JBRow>
178
+ ```
179
+
180
+ ## Pagination
181
+
182
+ The full React grid shows pagination from `pageIndex`, `pageSize`, `totalItemsCount`, and `totalPages`, and reports changes with `onPageIndexChange` and `onPageSizeChange`. If you need the standalone web-component pagination primitive, import and use `jb-pagination` from the web-component package directly.
183
+
184
+ ```jsx
185
+ import 'jb-grid/web-component/lib/pagination';
186
+ ```
187
+
188
+ See the web-component README for the standalone `pageIndex`, `min`, and `max` API.
189
+
190
+ ## Row & Cells
191
+
192
+ The React package exports `Row`, `Cell`, and `ExpandRow` wrappers for the underlying row/cell primitives.
193
+
194
+ ```jsx
195
+ <Row>
196
+ <Cell label="Name">Sara</Cell>
197
+ <Cell label="Age">32</Cell>
198
+ </Row>
199
+ ```
200
+
201
+ Use `Cell` for normal content, `ExpandRow` for expandable detail panels, and `label` on cells for the mobile card view.
202
+
199
203
  ## Styling
200
- | CSS variable name | description |
201
- | ------------- | ------------- |
202
- | --jb-grid-loading-color | list loading color |
203
- | --jb-grid-page-active-color | color of active page |
204
+ | CSS variable name | description |
205
+ | ------------- | ------------- |
206
+ | --jb-grid-footer-icon-fill-color-hover | footer icon hover fill color |
207
+ | --jb-grid-loading-color | list loading color |
208
+ | --jb-grid-page-color-active | color of active page |
204
209
 
205
210
  ## Shared Documentation
206
211
 
@@ -12,5 +12,4 @@ export type ContentProps = {
12
12
  errorComponent?: ReactNode;
13
13
  };
14
14
  declare function Content(props: ContentProps): React.JSX.Element;
15
- declare const _default: typeof Content;
16
- export default _default;
15
+ export default Content;
@@ -5,5 +5,4 @@ type FooterProps = {
5
5
  isFullscreen: boolean;
6
6
  };
7
7
  declare function Footer(props: FooterProps): React.JSX.Element;
8
- declare const _default: typeof Footer;
9
- export default _default;
8
+ export default Footer;