aio-table 8.0.1 → 9.1.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 (5) hide show
  1. package/index.css +169 -159
  2. package/index.d.ts +98 -0
  3. package/index.js +449 -2898
  4. package/package.json +26 -28
  5. package/README.md +0 -792
package/README.md DELETED
@@ -1,792 +0,0 @@
1
- # aio-table (React js all in one table)
2
-
3
- # aio table options
4
- - data table
5
- - tree table
6
- - support nested data
7
- - support flat data
8
- - keyboar navigation
9
- - inline edit
10
- - group by
11
- - sortable
12
- - filterable
13
- - searchable
14
- - use html or jsx in cells
15
- - freeze mode
16
- - resize columns
17
- - swap columns position
18
- - mobile support
19
- - paging
20
- # Installation
21
- ```javascript
22
- npm i aio-table
23
- ```
24
- # Basic
25
-
26
- #### countries JSON as aio table model:
27
- ```javascript
28
- [
29
- ...
30
- {
31
- "continent":"North America",
32
- "name":"United States",
33
- "population":"331853982",
34
- "percent":"4.21",
35
- "update":"16 Jun 2021"
36
- },
37
- ...
38
- ]
39
- ```
40
- ##### also you can find contries json in repository (countries.js)
41
-
42
- ```javascript
43
- import React,{Component} from "react";
44
- import Table from 'aio-table';
45
- import countries from './countries';
46
- import "./style.css";
47
-
48
- export default class App extends Component {
49
- state = {model:countries}
50
- render(){
51
- let {model} = this.state;
52
- return (
53
- <Table
54
- className='table'
55
- model={model}
56
- columns={[
57
- {
58
- title:'Name',
59
- getValue:(row)=>row.name,
60
- justify:false,
61
- titleJustify:false,
62
- search:true
63
- },
64
- {
65
- title:'Continent',
66
- getValue:(row)=>row.continent,
67
- width:120,
68
- },
69
- {
70
- title:'Population',
71
- getValue:(row)=>row.population,
72
- justify:false,
73
- width:120,
74
- },
75
- {
76
- title:'Percent',
77
- getValue:(row)=>row.percent,
78
- template:(row)=>row.percent + '%',
79
- width:90,
80
- }
81
- ]}
82
- paging={{
83
- number:1,
84
- size:20,
85
- }}
86
- padding={12}
87
-
88
- />
89
- );
90
- }
91
- }
92
-
93
- ```
94
- ![alt text](/images/1-basic.jpg)
95
-
96
- ### main props:
97
- props | type | default | description
98
- --------------- | -------------------------- | -------- | -----------
99
- model | json | Required | data model of table as rows.
100
- columns | array of objects | Required | list of table columns.
101
- paging | object | optional | configure table paging.
102
- groups | array of objects | optional | grouping rows.
103
- sorts | array of objects | optional | sorting rows
104
- className | string | optional | class name of table.
105
- id | string | optional | id of table.
106
- style | css object | optional | set table css style.
107
- padding | number | 12 | set table padding using padding props.(for better styling dont set padding in style instead set padding props)
108
- headerHeight | number | 36 | height of header.
109
- rowHeight | number | 36 | height of cells.
110
- rowGap | number | 6 | gap between rows.
111
- columnGap | number | 0 | gap between columns.
112
-
113
- ### each column Object:
114
- column property | type | default | description
115
- --------------- | -------------------------- | ----------------------------------------------- | -----------
116
- title | string | "" | title of column.
117
- getValue | function | optional if you set template property on column | get row object as parameter and returns value of table cell based on row.
118
- titleJustify | boolean | true | justifying column title.
119
- justify | boolean | true | justifying cell content.
120
- search | boolean | false | put search input in toolbar for searching rows based on column values.
121
- width | number or string or 'auto' | auto | set width of column
122
- minWidth | number or string | optional | set min width of column(use in resizing column)
123
- template | function | optional | get row as parameter and return cell html
124
- resizable | boolean | false | make column resizable
125
- movable | boolean | false | male column movable. (swaping columns)
126
- show | boolean | true | set column visibility
127
- toggleShow | boolean | false | set visibility of column by user from toolbar
128
- before | function | optional | get row as parameters and returns html as before cell content
129
- after | function | optional | get row as parameters and returns html as after cell content
130
-
131
- # Set column resizable
132
-
133
- ```javascript
134
- <Table
135
- ...
136
- columns={[
137
- ...
138
- {
139
- title:'Continent',
140
- getValue:(row)=>row.continent,
141
- width:120,
142
- resizable:true
143
- },
144
- ...
145
- ]}
146
- ...
147
- />
148
- ```
149
- ![alt text](/images/resize-column.gif)
150
-
151
- # Set column toggleShow
152
-
153
- ```javascript
154
- <Table
155
- ...
156
- columns={[
157
- ...
158
- {
159
- title:'Population',
160
- getValue:(row)=>row.population,
161
- justify:false,
162
- width:120,
163
- toggleShow:true
164
- },
165
- ...
166
- ]}
167
- ...
168
- />
169
-
170
- ```
171
- ![alt text](/images/column-toggleShow.gif)
172
- # Set column freeze (boolean)
173
-
174
- ##### default is false
175
-
176
- ```javascript
177
- <Table
178
- ...
179
- columns={[
180
- ...
181
- {
182
- title:'Name',
183
- getValue:(row)=>row.name,
184
- width:'auto',
185
- freeze:true
186
- },
187
- ...
188
- ]}
189
- ...
190
- />
191
-
192
- ```
193
- ![alt text](/images/freeze.gif)
194
-
195
- # Set column toggleFreeze (boolean)
196
-
197
- ##### if true user can set column freeze from toolbar.
198
- ##### default is false
199
-
200
- ```javascript
201
- <Table
202
- ...
203
- columns={[
204
- ...
205
- {
206
- title:'Name',
207
- getValue:(row)=>row.name,
208
- width:'auto',
209
- toggleFreeze:true
210
- },
211
- {
212
- title:'Population',resizable:true,
213
- getValue:(row)=>row.population,
214
- template:(row)=>numberWithCommas(row.population),
215
- width:'160px',
216
- toggleFreeze:true
217
- }
218
- ...
219
- ]}
220
- ...
221
- />
222
-
223
- ```
224
- ![alt text](/images/togglefreeze.gif)
225
-
226
-
227
- # sizing props (headerHeight,rowHeight,rowGap,columnGap,padding)
228
-
229
- default value is 36
230
- ```javascript
231
- <Table
232
- ...
233
- headerHeight={24}
234
- rowHeight={36}
235
- rowGap={8}
236
- columnGap={1}
237
- padding={12}
238
- ...
239
- />
240
- ```
241
- ![alt text](/images/sizing-props.jpg)
242
-
243
-
244
- # set column movable (boolean)
245
- ##### drag and drop movable columns to swap and reorder.
246
- ##### default is true
247
- ##### for prevent move column set movable property false on column object
248
-
249
- ```javascript
250
- <Table
251
- ...
252
- columns={[
253
- ...
254
- {
255
- title:'Population',
256
- getValue:(row)=>row.population,
257
- movable:false
258
- }
259
- ...
260
- ]}
261
- ...
262
- />
263
-
264
- ```
265
- ![alt text](/images/movable.gif)
266
- # set column filter (object)
267
- ##### filter rows by column value automatically.
268
- ##### for filter rows based on column , getValue property is required on column.
269
- property | type | default | description
270
- -------- | --------------------------- | ------- | -----------
271
- type | string ('text' or 'number') | 'text' | based on column values.
272
-
273
- ```javascript
274
- <Table
275
- ...
276
- columns={[
277
- {
278
- title:'Name',
279
- getValue:(row)=>row.name,
280
- justify:false,
281
- titleJustify:false,
282
- filter:{type:'text'}
283
- },
284
- {
285
- title:'Continent',
286
- getValue:(row)=>row.continent,
287
- width:120,
288
- resizable:true,
289
- },
290
- {
291
- title:'Population',
292
- getValue:(row)=>row.population,
293
- justify:false,
294
- width:120,
295
- filter:{type:'number'}
296
- },
297
- {
298
- title:'Percent',
299
- getValue:(row)=>row.percent,
300
- template:(row)=>row.percent + '%',
301
- width:90,
302
- }
303
- ]}
304
- ...
305
- />
306
-
307
- ```
308
- ![alt text](/images/column-filter.gif)
309
- ##### if you want to filter rows outside of aio table , you can set onChangeFilter props (for example server side filtering)
310
- ```javbascript
311
- <Table
312
- ...
313
- onChangeFilter={(filters)=>{
314
- ....
315
- }}
316
- ...
317
- />
318
- ```
319
- ##### filters is an array of objects . each object has 3 property (booleanType,items,column)
320
-
321
- # set paging (object)
322
- ##### paging rows.
323
- ##### properties:
324
-
325
- property | Type | Default | Description
326
- -------- | ----- | ------- | -----------
327
- sizes | Array | [1,5,10,20,30] | page sizes (dropdown)
328
- size | number | first index of sizes property | rows count per page
329
- number | number | 1 | page number
330
- onChange | function | Optional | if you set onChange , you must paging rows of model in parent component and aio table will not paging rows automatically
331
-
332
- onChange function get changed paging object as parameters
333
-
334
- ```javascript
335
- <Table
336
- ...
337
- paging={{
338
- number:1,
339
- sizes:[5,10,15,20],
340
- size:10,
341
- onChange:(paging)=>{
342
- //change model props
343
- //if not set onChange , paging will be automatically on model
344
- }
345
- }}
346
- ...
347
- />
348
- ```
349
-
350
- # Set column before and after (function)
351
-
352
- ##### set html before and after cells of column content.
353
-
354
- ```javascript
355
- <Table
356
- ...
357
- columns={[
358
- ...
359
- {
360
- title:'Name',
361
- getValue:(row)=>row.name,
362
- before:(row)=>{
363
- return (
364
- <div
365
- style={{
366
- background:'dodgerblue',
367
- color:'#fff',
368
- borderRadius:'100%',
369
- width:20,
370
- height:20,
371
- display:'flex',
372
- alignItems:'center',
373
- justifyContent:'center',
374
- fontSize:10
375
- }}
376
- >{row._index}</div>
377
- )
378
- },
379
- after:(row)=>{
380
- var colors = {
381
- 'Asia':'orange','North America':'blue','South America':'lightblue','Africa':'black','Europe':'green'
382
- }
383
- return (
384
- <div
385
- style={{
386
- background:colors[row.continent],
387
- color:'#fff',
388
- padding:'0 6px',
389
- height:'16px',
390
- fontSize:'10px',
391
- lineHeight:'16px',
392
- textAlign:'center',
393
- borderRadius:'3px'
394
- }}
395
- >{row.continent}</div>
396
- )
397
- }
398
- },
399
- ...
400
- ]}
401
- ...
402
- />
403
- ```
404
- ![alt text](/images/column-before-after.jpg)
405
- # Set groups (Array Of Objects)
406
-
407
- ##### group by rows.
408
- ##### each group properties:
409
- Property | Type | Default | Description
410
- -------- | ---- | ------- | -----------
411
- title | string | Required | uniqe title of group item
412
- getValue | function | Required | this function get (row) as parameter and return a value category for group by rows.
413
- active | boolean | true | active or deactive group item.
414
- toggle | boolean | true | if true, user can toggle activity of group item from toolbar
415
-
416
- ```javascript
417
- <Table
418
- ...
419
- groups:[
420
- {
421
- title:'Continent',
422
- getValue:(row)=>{
423
- return row.continent;
424
- }
425
- }
426
- }
427
- ...
428
- />
429
- ```
430
- ![alt text](/images/groupby-1.gif)
431
- ##### Other Example:
432
-
433
- ```javascript
434
- <Table
435
- ...
436
- groups={[
437
- {
438
- title:'Populatuion',
439
- getValue:(row)=>{
440
- if(row.population > 1000000000){
441
- return 'More than 1,000,000,000'
442
- }
443
- if(row.population > 500000000){
444
- return 'Between 500,000,000 and 1,000,000,000'
445
- }
446
- if(row.population > 100000000){
447
- return 'Between 100,000,000 and 500,000,000'
448
- }
449
- if(row.population > 50000000){
450
- return 'Between 50,000,000 and 100,000,000'
451
- }
452
- if(row.population > 25000000){
453
- return 'Between 25,000,000 and 50,000,000'
454
- }
455
- return 'Less Than 25,000,000'
456
- }
457
- }
458
- ]}
459
- ...
460
- />
461
- ```
462
- ![alt text](/images/groupby-2.gif)
463
-
464
- # Set sorts (Array Of Objects)
465
-
466
- ##### sort rows.
467
- ##### each sort properties:
468
- Property | Type | Default | Description
469
- -------- | ---- | ------- | -----------
470
- title | string | Required | uniqe title of sort item
471
- getValue | function | Required | this function get (row) as parameter and return a value for sort rows.
472
- type | string ('inc' or 'dec') | 'inc' | set sort type as increase or decrease.
473
- active | boolean | true | active or deactive sort item.
474
- toggle | boolean | true | if true, user can toggle activity of sort item from toolbar
475
-
476
- ```javascript
477
- <Table
478
- ...
479
- sorts={[
480
- {
481
- title:'Name',
482
- getValue:(row)=>row.name,
483
- type:'inc'
484
- }
485
- ]}
486
- ...
487
- />
488
- ```
489
- ![alt text](/images/sorts.gif)
490
- # Set column inlineEdit (Objects)
491
-
492
- ##### inline editing cells.
493
- ##### inlineEdit properties:
494
- Property | Type | Default | Description
495
- -------- | ---- | ------- | -----------
496
- type | 'text' or 'number' or 'select' | 'text' | type of inline edit input.
497
- disabled | function | Optional | get row as parameter and return boolean. if return true this cell input will be disabled.
498
- options | array of objects | required if type is 'select' | options of inline edit input by select type (each option have 2 property(text,value)).
499
- onChange | function | required | get row and value as parameters. if return an string means there is an error and cell will show this string as error message.
500
-
501
- ```javascript
502
- <Table
503
- ...
504
- columns={[
505
- {
506
- title:'Name',
507
- getValue:(row)=>row.name,
508
- width:'auto',
509
- inlineEdit:{
510
- type:'text',
511
- onChange:(row,value)=>{
512
- row.name = value;
513
- this.setState({model:this.state.model})
514
- }
515
- }
516
- },
517
- {
518
- title:'Population',resizable:true,
519
- getValue:(row)=>row.population,
520
- template:(row)=>numberWithCommas(row.population),
521
- width:'100px',
522
- inlineEdit:{
523
- type:'number',
524
- onChange:(row,value)=>{
525
- row.population = value;
526
- this.setState({model:this.state.model})
527
- }
528
- }
529
- },
530
- {
531
- title:'Percent',
532
- getValue:(row)=>row.percent,
533
- template:(row)=>row.percent + '%',
534
- width:'70px'
535
- },
536
- {
537
- title:'Continent',
538
- getValue:(row)=>row.continent,
539
- width:'120px',
540
- inlineEdit:{
541
- type:'select',
542
- options:[
543
- {text:'Asia',value:'Asia'},
544
- {text:'Africa',value:'Africa'},
545
- {text:'Europa',value:'Europa'},
546
- {text:'North America',value:'North America'},
547
- {text:'South America',value:'South America'}
548
- ],
549
- onChange:(row,value)=>{
550
- row.continent = value;
551
- this.setState({model:this.state.model})
552
- }
553
- }
554
- }
555
- ]}
556
- ...
557
- />
558
- ```
559
- ![alt text](/images/inlineedit.gif)
560
-
561
- # Tree data (nested json)
562
-
563
- ##### nested json example:
564
- ```javascript
565
- let nestedData = [
566
- {
567
- name:'Applications',id:'1',
568
- childs:[
569
- {name:'Calendar',id:'2',type:'app'},
570
- {name:'Chrome',id:'3',type:'app'},
571
- {name:'Webstorm',id:'4',type:'app'}
572
- ]
573
- },
574
- {
575
- name:'Documents',id:'5',
576
- childs:[
577
- {
578
- name:'Angular',id:'6',
579
- childs:[
580
- {
581
- name:'SRC',id:'7',
582
- childs:[
583
- {name:'Compiler',id:'8',type:'ts'},
584
- {name:'Core',id:'9',type:'ts'},
585
- ]
586
- },
587
- ]
588
- },
589
- {
590
- name:'Material2',id:'10',
591
- childs:[
592
- {
593
- name:'SRC',id:'11',
594
- childs:[
595
- {name:'Button',id:'12',type:'ts'},
596
- {name:'Checkbox',id:'13',type:'ts'},
597
- {name:'Input',id:'14',type:'ts'}
598
- ]
599
- }
600
- ]
601
- },
602
- ]
603
- },
604
- {
605
- name:'Downloads',id:'15',
606
- childs:[
607
- {name:'October',id:'16',type:'pdf'},
608
- {name:'November',id:'17',type:'pdf'},
609
- {name:'Tutorial',id:'18',type:'pdf'}
610
- ]
611
- },
612
- {
613
- name:'Pictures',id:'19',
614
- childs:[
615
- {
616
- name:'Library',id:'20',
617
- childs:[
618
- {name:'Contents',id:'21',type:'dir'},
619
- {name:'Pictures',id:'22',type:'dir'}
620
- ]
621
- },
622
- {name:'Sun',id:'23',type:'png'},
623
- {name:'Woods',id:'24',type:'jpg'}
624
- ]
625
- }
626
- ]
627
- ```
628
-
629
- ##### set getRowChilds function for get rows childs.
630
- ##### set column treeMode for collapse and indent rows.
631
- ```javascript
632
- export default class App extends Component {
633
- render(){
634
- return (
635
- <Table
636
- className='table'
637
- model={nestedData}
638
- columns={[
639
- {
640
- title:'Name',
641
- getValue:(row)=>row.name,
642
- justify:false,
643
- titleJustify:false,
644
- treeMode:true
645
- },
646
- {
647
- title:'Type',
648
- getValue:(row)=>row.type
649
- }
650
- ]}
651
- getRowChilds={(row)=>row.childs}
652
- />
653
- );
654
- }
655
- }
656
- ```
657
- ![alt text](/images/tree-nested.gif)
658
-
659
- # Tree data (flat json)
660
-
661
- ##### data as array with id and parent id.
662
- ##### flat json example:
663
- ```javascript
664
- let flatData = [
665
- {name:'Applications',id:'1'},
666
- {name:'Calendar',id:'2',type:'app',parentId:'1'},
667
- {name:'Chrome',id:'3',type:'app',parentId:'1'},
668
- {name:'Webstorm',id:'4',type:'app',parentId:'1'},
669
- {name:'Documents',id:'5'},
670
- {name:'Angular',id:'6',parentId:'5'},
671
- {name:'SRC',id:'7',parentId:'6'},
672
- {name:'Compiler',id:'8',type:'ts',parentId:'7'},
673
- {name:'Core',id:'9',type:'ts',parentId:'7'},
674
- {name:'Material2',id:'10',parentId:'5'},
675
- {name:'SRC',id:'11',parentId:'10'},
676
- {name:'Button',id:'12',type:'ts',parentId:'11'},
677
- {name:'Checkbox',id:'13',type:'ts',parentId:'11'},
678
- {name:'Input',id:'14',type:'ts',parentId:'11'},
679
- {name:'Downloads',id:'15'},
680
- {name:'October',id:'16',type:'pdf',parentId:'15'},
681
- {name:'November',id:'17',type:'pdf',parentId:'15'},
682
- {name:'Tutorial',id:'18',type:'pdf',parentId:'15'},
683
- {name:'Pictures',id:'19'},
684
- {name:'Library',id:'20',parentId:'19'},
685
- {name:'Contents',id:'21',type:'dir',parentId:'20'},
686
- {name:'Pictures',id:'22',type:'dir',parentId:'20'},
687
- {name:'Sun',id:'23',type:'png',parentId:'19'},
688
- {name:'Woods',id:'24',type:'jpg',parentId:'19'}
689
- ]
690
- ```
691
- ##### set getRowParentId function for get rows parent id.
692
- ##### set getRowId function for get rows id.
693
- ##### set column treeMode for collapse and indent rows.
694
- ```javascript
695
- export default class App extends Component {
696
- render(){
697
- return (
698
- <Table
699
- className='table'
700
- model={flatData}
701
- columns={[
702
- {
703
- title:'Name',
704
- getValue:(row)=>row.name,
705
- justify:false,
706
- titleJustify:false,
707
- treeMode:true
708
- },
709
- {
710
- title:'Type',
711
- getValue:(row)=>row.type
712
- }
713
- ]}
714
- getRowId={(row)=>row.id}
715
- getRowParentId={(row)=>row.parentId}
716
- />
717
- );
718
- }
719
- }
720
- ```
721
- ![alt text](/images/tree-nested.gif)
722
-
723
- # Gantt chrt example
724
-
725
- ##### for set column as gantt chart , you can set a column by template:'gantt'.
726
- ##### gantt column can have all column properties and must have this properties:
727
- Property | Type | Default | Description
728
- -------- | ---- | ------- | -----------
729
- template | string('gantt') | Required | define column as gantt.
730
- getKeys | function | Required | return gantt keys array.
731
- getStart | function | required | get row a parameter and return an string as start of row bar(one of keys).
732
- getEnd | function | required | get row a parameter and return an string as end of row bar(one of keys).
733
- getProgress | function | Optional | get row as parameter and return a number between 0 and 100 to show row percentage graphically.
734
- getText | function | Optional | get row as parameter and return an string to show on row gantt bar.
735
- padding | string(px) | '36px' | gantt horizontal padding.
736
- getBackgroundColor | function | a function that return '#69bedb' | get row as parameter and return an string as gant bar background color.
737
- getColor | function | a function that return '#fff' | get row as parameter and return an string as gant bar text color.
738
- getFlags | function | Optional | return an array of objects (Examplae [{color:'red',value:'2022/6'}]) as gantt flags.
739
- ```javascript
740
- export default class App extends Component {
741
- state = {
742
- model:[
743
- {name:'a',startDate:'2022/1',endDate:'2022/6',progress:10},
744
- {name:'b',startDate:'2022/1',endDate:'2022/3',progress:20},
745
- {name:'c',startDate:'2022/3',endDate:'2022/6',progress:50},
746
- {name:'d',startDate:'2022/6',endDate:'2022/9',progress:30},
747
- {name:'e',startDate:'2022/9',endDate:'2022/12',progress:100},
748
- {name:'f',startDate:'2022/1',endDate:'2022/9',progress:80},
749
- {name:'g',startDate:'2022/3',endDate:'2022/9',progress:70},
750
- {name:'h',startDate:'2022/6',endDate:'2022/12',progress:60},
751
- {name:'i',startDate:'2022/9',endDate:'2022/12',progress:50},
752
- ]
753
- }
754
- render(){
755
- var {model} = this.state;
756
- return (
757
- <Table
758
- model={model}
759
- columns={[
760
- {
761
- title:'Name',
762
- getValue:(row)=>row.name,
763
- width:'80px',
764
- },
765
- {
766
- title:'My Gantt',
767
- minWidth:'400px',
768
- toggleShow:true,
769
-
770
- template:'gantt',
771
- getStart:(row)=>row.startDate,
772
- getEnd:(row)=>row.endDate,
773
- getKeys:()=>['2022/1','2022/2','2022/3','2022/4','2022/5','2022/6','2022/7','2022/8','2022/9','2022/10','2022/11','2022/12'],
774
- getProgress:(row)=>row.progress,
775
- getText:(row)=>row.name + ' ' + row.progress + '%',
776
- padding:'24px',
777
- getBackgroundColor:(row)=>'lightblue',
778
- getColor:(row)=>'#fff',
779
- getFlags:()=>[
780
- {color:'red',value:'2022/6'},
781
- {color:'red',value:'2022/9'},
782
- ]
783
- }
784
- ]}
785
- />
786
- );
787
- }
788
- }
789
-
790
- ```
791
- ![alt text](/images/ganttchart.jpg)
792
-