forked from olifolkerd/tabulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.html
988 lines (796 loc) · 35.7 KB
/
examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
<html>
<head>
<title>Tabulator - Live Demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="tabulator.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="tabulator.js"></script>
</head>
<body>
<style type="text/css">
body{
padding:20px 40px;
font-family: 'Montserrat', sans-serif !important;
}
header{
font-weight: bold;
font-size: 30px;
}
header span{
vertical-align: middle;
font-size: .5em;
color: #999;
}
header span a{
font-size: .9em;
}
section:first-of-type header{
font-size: 50px;
}
section{
margin-bottom:30px;
}
ul>li{
margin-bottom:2px;
}
button, select{
margin-right:20px;
}
input{
font-family: 'Montserrat', sans-serif !important;
}
</style>
<script type="text/javascript">
//sample data to be used in all tabulators
var tabledata = [
{id:1, name:"Oli Bob \n steve", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1, lucky_no:5},
{id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true, lucky_no:10},
{id:3, name:"Christine Lobowski", age:"42", height:0, col:"green", dob:"22/05/1982", cheese:"true", lucky_no:12},
{id:4, name:"Brendon Philips", age:"125", gender:"male", height:1, col:"orange", dob:"01/08/1980", lucky_no:18},
{id:5, name:"Margret Marmajuke", age:"16", gender:"female", height:5, col:"yellow", dob:"31/01/1999", lucky_no:33},
{id:6, name:"Frank Harbours", age:"38", gender:"male", height:4, col:"red", dob:"", cheese:1, lucky_no:2},
{id:7, name:"Jamie Newhart", age:"23", gender:"male", height:3, col:"green", dob:"14/05/1985", cheese:true, lucky_no:63},
{id:8, name:"Gemma Jane", age:"60", height:0, col:"red", dob:"22/05/1982", cheese:"true", lucky_no:72},
{id:9, name:"Emily Sykes", age:"42", gender:"female", height:1, col:"maroon", dob:"11/11/1970", lucky_no:44},
{id:10, name:"James Newman", age:"73", gender:"male", height:5, col:"red", dob:"22/03/1998", lucky_no:9},
];
</script>
<section>
<header>Tabulator</header>
<p>An easy to use table generation JQuery UI Plugin</p>
<p>Tabulator allows you to create a table with in seconds from any JSON formatted data.</p>
<p>It relies on no external css or images, simply include the library in your JQuery UI project and you're away!</p>
<p>Tabulator is packed with useful features including:
<ul>
<li>JSON, array or AJAX data loading</li>
<li>Column sorting</li>
<li>Custom data formatting</li>
<li>Resizable columns</li>
<li>Auto scaling to fit data/element</li>
<li>Many theming options</li>
<li>Custom click and context Events</li>
<li>Callbacks at every stage of data processing and rendering</li>
</ul>
</p>
<div id="example-table-demo"></div>
<script type="text/javascript">
var printIcon = function(value, data, cell, row, options){ //plain text value
return "<i class='fa fa-print' style='vertical-align:middle; padding:2px 0;'></i> "
};
$("#example-table-demo").tabulator({
height:"320px",
fitColumns:true,
tooltips:true,
tooltipsHeader:true,
movableCols:true,
columns:[
{formatter:printIcon, width:40, align:"center",onClick:function(e, cell, val, data){alert("Printing row data for: " + data.name)} },
{title:"Name", field:"name", sorter:"string", width:150, tooltipHeader:"Custom Header Tooltip"},
{title:"Age", field:"age", sorter:"number", align:"left", formatter:"progress"},
{title:"Gender", field:"gender", width:100, sorter:"string", onClick:function(e, val, cell, data){console.log("cell click - " + val, cell)}},
{title:"Height", field:"height", formatter:"star", align:"center", sorter:"number", width:100},
{title:"Favourite Color", field:"col", sorter:"string", sortable:false},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross", sorter:"boolean"},
],
rowClick:function(e, id, data, row){
alert("Row " + id + " Clicked!!!!")
},
rowContext:function(e, id, data, row){
alert("Row " + id + " Context Clicked!!!!")
},
});
$("#example-table-demo").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-demo").tabulator("redraw");
});
</script>
</section>
<section>
<header>Simple Table</header>
<p>
In its simplest form, all you need to set in the options are the column titles and field names.
</p>
<p>
By default columns are resizable (using edge of column header) and sortable (as strings).
</P>
<div id="example-table-simple"></div>
<script type="text/javascript">
$("#example-table-simple").tabulator({
height:"320px",
data:tabledata,
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", width:60, sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", width:80},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob"},
{title:"Likes Cheese", field:"cheese"},
],
});
$(window).resize(function(){
$("#example-table-simple").tabulator("redraw");
});
</script>
</section>
<section>
<header>Fit To Data <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#fittodata">http://olifolkerd.github.io/tabulator/docs/#fittodata</a></span></header>
<p>
Tables will automatically resize to fit the data
</p>
<div id="example-table-fittodata"></div>
<script type="text/javascript">
$("#example-table-fittodata").tabulator({
height:"320px",
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", width:60, align:"right", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", align:"center", width:80},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center"},
],
});
$("#example-table-fittodata").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-fittodata").tabulator("redraw");
});
</script>
</section>
<section>
<header>Fit To Width <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#fittowidth">http://olifolkerd.github.io/tabulator/docs/#fittowidth</a></span></header>
<p>
By setting the <span><strong>fitColumns</strong></span> to true, the table will resize columns so that they fit perfectly inside the width of the container.
</p>
<p>
If a width is specified on any columns, where possible the columns will be set at this width and other columns will be resized around them. If there is not enough space to fit all the columns in, then all column widths are ignored and they are sized equally.
</p>
<div id="example-table-fittowidth"></div>
<script type="text/javascript">
$("#example-table-fittowidth").tabulator({
height:"320px",
fitColumns:true,
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", align:"right", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", align:"center", width:60},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center"},
],
});
$("#example-table-fittowidth").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-fittowidth").tabulator("redraw");
});
</script>
</section>
<section>
<header>Parse Data from Table Element</header>
<p>It is possible to turn a standard HTML Table element into a tabulator, pulling all the data directly from the table into the tabulator when it is created.</p>
<table id="example-table-table" tabulator-fitColumns="true">
<thead>
<tr>
<th width="200">Name</th>
<th tabulator-align="center">Age</th>
<th>Gender</th>
<th>Height</th>
<th>Favourite Color</th>
<th>Date of Birth</th>
<th>Likes Cheese</th>
</tr>
</thead>
<tbody>
<tr>
<td>Oli Bob</td>
<td>12</td>
<td>male</td>
<td>1</td>
<td>red</td>
<td></td>
<td>1</td>
</tr>
<tr>
<td>Mary May</td>
<td>1</td>
<td>female</td>
<td>2</td>
<td>blue</td>
<td>14/05/1982</td>
<td>true</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$("#example-table-table").tabulator({});
</script>
</section>
<section>
<header>Editable Data <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#manipulating-data">http://olifolkerd.github.io/tabulator/docs/#manipulating-data</a></span></header>
<p>
Using the <strong>editable</strong> setting on each column, you can make a user editable table.
</p>
<p>
Any time a cell is edited it triggers the <strong>rowEdit</strong> callback, to allow you to process any changes.
</p>
<p>
You can call the <strong>getData</strong> method to get an array of all of the tables data, including any edits
</p>
<div id="example-table-editable"></div>
<script type="text/javascript">
//custom editor
var genderEditor = function(cell, value){
//cell - JQuery object for current cell
//value - the current value for current cell
//create and style editor
var editor = $("<select><option value=''></option><option value='male'>male</option><option value='female'>female</option></select>");
editor.css({
"padding":"4px",
"width":"100%",
"box-sizing":"border-box",
})
//Set value of editor to the value of the cell
.val(value);
//set focus on the select box when the editor is selected (timeout allows for editor to be added to DOM)
setTimeout(function(){
editor.focus();
},100)
//when the value has been set, update the cell
editor.on("change blur", function(e){
cell.trigger("editval", editor.val());
});
//return the editor element
return editor;
}
$("#example-table-editable").tabulator({
height:"320px",
columns:[
{title:"Name", field:"name", width:200, editable:true, editable:true},
{title:"Age", field:"age", sorter:"number", align:"left", formatter:"progress", width:200, editable:true},
{title:"Gender", field:"gender", editable:true, editor:genderEditor},
{title:"Height", field:"height", formatter:"star", align:"center", width:100, editable:true},
{title:"Favourite Color", field:"col", editable:true},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date", editable:true},
{title:"Likes Cheese", field:"cheese", align:"center", editable:true, formatter:"tickCross"},
{title:"Luck No", field:"lucky_no", align:"right", width:100, sorter:"number", editor:"number"},
],
rowEdit:function(id,data,row){
},
});
$("#example-table-editable").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-editable").tabulator("redraw");
});
</script>
</section>
<section>
<header>Sorters <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#sorting">http://olifolkerd.github.io/tabulator/docs/#sorting</a></span></header>
<p>Sorting is enabled by default, and can be toggled on or off by column using the <span><strong>sortable</strong></span> option.</p>
<p>By default all columns are sorted as text, different sort functions can be set using the <span><strong>sorter</strong></span> option
<ul>
<li><strong>string</strong> - sorts column as strings of characters</li>
<li><strong>number</strong> - sorts column as numbers (integer or float, will also handle numbers using "," seperators)</li>
<li><strong>alphanum</strong> - sorts column as alpha numeric code</li>
<li><strong>boolean</strong> - sorts column as booleans</li>
<li><strong>date</strong> - sorts column as dates (for this you will need to set the date format using the <span><strong>dateFormat</strong></span> option when you create your table. default format is "dd/mm/yyyy")</li>
</ul>
</p>
<p>You can define a custom sorter functions in the sorter option if you need bespoke sorting functionality.</p>
<p>You can programmatically trigger a sort using the <strong>sort</strong> function.</p>
<p>
<fieldset>
<legend>Programmatic Sort</legend>
<label>Field: </label>
<select id="sort-field">
<option value="name" selected>Name</option>
<option value="age">Age</option>
<option value="gender">Gender</option>
<option value="height">Height</option>
<option value="col">Favourite Colour</option>
<option value="dob">Date Of Birth</option>
<option value="cheese">Likes Cheese</option>
</select>
<label>Direction:</label>
<select id="sort-direction">
<option value="asc" selected>asc</option>
<option value="desc">desc</option>
</select>
<input id="sort-trigger" type="button" value="Trigger Sort" style="margin-left:40px;">
</fieldset>
</p>
<div id="example-table-sorting"></div>
<script type="text/javascript">
$("#example-table-sorting").tabulator({
height:"320px",
fitColumns:true,
sortBy:"name",
sortDir:"asc",
columns:[
{title:"Name", field:"name", sorter:"string", width:200},
{title:"Age", field:"age", sorter:"number", align:"right", sorter:"number"},
{title:"Gender", field:"gender", sorter:"string"},
{title:"Height", field:"height", align:"center", width:100},
{title:"Favourite Color", field:"col", sortable:false, sorter:function(a,b){
return String(a).toLowerCase().localeCompare(String(b).toLowerCase());
}},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", sorter:"boolean"},
],
});
$("#example-table-sorting").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-sorting").tabulator("redraw");
});
$("#sort-trigger").click(function(){
$("#example-table-sorting").tabulator("sort", $("#sort-field").val(), $("#sort-direction").val());
})
</script>
</section>
<section>
<header>Formatters <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#formatting">http://olifolkerd.github.io/tabulator/docs/#formatting</a></span></header>
<p></p>
<p>Tabulator allows you to format your data in a wide variety of ways, so your tables can display information in a more graphical and clear layout.</p>
<p>you can set formatters on a per column basis using the <span><strong>formatter</strong></span> option in the column data.</p>
<p>
Tabulator comes with a number of preconfigured formatters including:
<ul>
<li><strong>money</strong> - formats a number into a currency notation (eg. 1234567.8901 -> 1,234,567.89)</li>
<li><strong>email</strong> - renders data as an anchor with a mailto: link to the given value</li>
<li><strong>link</strong> - renders data as an anchor with a link to the given value</li>
<li><strong>tick</strong> - displays a green tick if the value is (true|'true'|'True'|1) and an empty cell if not</li>
<li><strong>tickCross</strong> - displays a green tick if the value is (true|'true'|'True'|1) and a red cross if not</li>
<li><strong>color</strong> - sets the background color of the cell to the value. Can be any valid css colour eg. #ff0000, #f00, rgb(255,0,0), red, rgba(255,0,0,0), hsl(0, 100%, 50%)</li>
<li><strong>star</strong> - displays a graphical 0-5 star rating based on integer values from 0-5</li>
<li><strong>progress</strong> - displays a progress bar that fills the cell from left to right, using values 0-100 as a percentage of width</li>
<li><strong>buttonTick</strong> - displays a tick icon on eac row (for use as a button)</li>
<li><strong>buttonCross</strong> - displays a cross icon on eac row (for use as a button)</li>
</ul>
</p>
<p>You can define a custom formatter function in the formatter option if you need more bespoke formatter functionality</p>
<p>You can create icon/button columns, by not specifying a field parameter in the column data and creating a custom formatter for the column contents. In the example below we have created a print button on the left of each row.</p>
<p>You can also set a row formatter using the <strong>rowFormatter</strong> option, this allows you to format the styling of the row as a whole</p>
<div id="example-table-formatter"></div>
<script type="text/javascript">
var printIcon = function(value, data, cell, row, options){ //plain text value
return "<i class='fa fa-print'></i> "
};
$("#example-table-formatter").tabulator({
height:"320px",
fitColumns:true,
rowFormatter:function(row, data){
if(data.col == "blue"){
row.css({"background-color":"#A6A6DF"});
}
},
columns:[
{formatter:printIcon, width:40, align:"center", onClick:function(e, cell, val, data){alert("Printing row data for: " + data.name)}},
{title:"Name", field:"name", width:200, formatter:function(value, data, cell, row, options){
if(value.indexOf("o") > 0){
return "<span style='color:red; font-weight:bold;'>" + value + "</span>";
}else{
return value;
}
}},
{title:"Age", field:"age", formatter:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
{title:"Favourite Color", field:"col" ,formatter:"color", width:160},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{formatter:"buttonCross", width:30, align:"center"},
],
});
$("#example-table-formatter").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-formatter").tabulator("redraw");
});
</script>
</section>
<section>
<header>Grouping Data <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#grouping">http://olifolkerd.github.io/tabulator/docs/#grouping</a></span></header>
<p></p>
<p>You can group rows together using the <strong>groupBy</strong> option. To group by a field, set this option to the name of the field.</p>
<p>To group by more complex operations you should pass a function that returns a string that represents the group.</p>
<div id="example-table-grouping"></div>
<script type="text/javascript">
var printIcon = function(value, data, cell, row, options){ //plain text value
return "<i class='fa fa-print'></i> "
};
$("#example-table-grouping").tabulator({
height:"320px",
fitColumns:true,
groupBy:"gender",
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", formatter:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
],
});
$("#example-table-grouping").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-grouping").tabulator("redraw");
});
</script>
</section>
<section>
<header>Filter Data <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#filtering">http://olifolkerd.github.io/tabulator/docs/#filtering</a></span></header>
<p></p>
<p>Tabulator allows you to filter the table data by any field in the data set.</p>
<p>To set a filter you need to call the <strong>setFilter</strong> method, passing the field you wish to filter, the comparison type and the value to filter for</p>
<p>
Tabulator comes with a number of filter comparison types including:
<ul>
<li><strong>=</strong> - Displays only rows with data that is the same as the filter</li>
<li><strong><</strong> - displays rows with a value less than the filter value</li>
<li><strong><=</strong> - displays rows with a value less than or qual to the filter value</li>
<li><strong>></strong> - displays rows with a value greater than the filter value</li>
<li><strong>>=</strong> - displays rows with a value greater than or qual to the filter value</li>
<li><strong>!=</strong> - displays rows with a value that is not equal to the filter value</li>
<li><strong>like</strong> - displays any rows with data that contains the specified string anywhere in the specified field. (case insesitive)</li>
</ul>
</p>
<p>
<fieldset>
<legend>Filter Parameters</legend>
<label>Field: </label>
<select id="filter-field">
<option></option>
<option value="name">Name</option>
<option value="age">Age</option>
<option value="gender">Gender</option>
<option value="height">Height</option>
<option value="col">Favourite Colour</option>
<option value="dob">Date Of Birth</option>
<option value="cheese">Likes Cheese</option>
<option value="function">Likes Cheese & height < 3</option>
</select>
<label>Type:</label>
<select id="filter-type">
<option value="=">=</option>
<option value="<"><</option>
<option value="<="><=</option>
<option value=">">></option>
<option value=">=">>=</option>
<option value="!=">!=</option>
<option value="like">like</option>
</select>
<label>Value: </label><input id="filter-value" type="text" placeholder="value to filter">
<input id="filter-clear" type="button" value="Clear Filter" style="margin-left:40px;">
</fieldset>
</p>
<div id="example-table-filters"></div>
<script type="text/javascript">
function customFilter(data){
return data.cheese && data.height < 3;
}
function updateFilter(){
var filter = $("#filter-field").val() == "function" ? customFilter : $("#filter-field").val();
if($("#filter-field").val() == "function" ){
$("#filter-type").prop("disabled", true);
$("#filter-value").prop("disabled", true);
}else{
$("#filter-type").prop("disabled", false);
$("#filter-value").prop("disabled", false);
}
$("#example-table-filters").tabulator("setFilter", filter, $("#filter-type").val(), $("#filter-value").val());
}
$("#filter-field, #filter-type").change(updateFilter);
$("#filter-value").keyup(updateFilter);
$("#filter-clear").click(function(){
$("#filter-field").val("");
$("#filter-type").val("=");
$("#filter-value").val("");
$("#example-table-filters").tabulator("clearFilter");
});
$("#example-table-filters").tabulator({
height:"320px",
fitColumns:true,
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", formatter:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
],
});
$("#example-table-filters").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-filters").tabulator("redraw");
});
</script>
</section>
<section>
<header>Pagination<span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#pagination">http://olifolkerd.github.io/tabulator/docs/#pagination</a></span></header>
<p>Tabulator allows you to paginate your data. simply set the <strong>pagination</strong> property to true.</p>
<p>If you have set the height of the table then the data will be automatically paginated to fit within the table.</p>
<p>If you wish to define how many rows should be shown on a page, set this in the <strong>paginationSize</strong> property. If you set the paginationSize without setting the height, the Tabulator will automatically resize to fit the data</p>
<div id="example-table-pagination"></div>
<script type="text/javascript">
var printIcon = function(value, data, cell, row, options){ //plain text value
return "<i class='fa fa-print'></i> "
};
$("#example-table-pagination").tabulator({
height:"166px",
fitColumns:true,
pagination:true,
// paginationSize:4,
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", formatter:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
],
});
$("#example-table-pagination").tabulator("setData", tabledata);
$("#example-table-pagination").tabulator("setPage", 1);
$(window).resize(function(){
$("#example-table-pagination").tabulator("redraw");
});
</script>
</section>
<section>
<header>Persistent Column Layout <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#persistant-columns">http://olifolkerd.github.io/tabulator/docs/#persistant-columns</a></span></header>
<p>
Tabulator can store the layout of columns in a cookie so that each time a user comes back to the page the table is laid out just as they left it.
</p>
<p>
Try resizing (drag the right edge of a column header) or rearranging (drag the middle of a column header) the columns of this table, then refresh the page. your new layout will persist.
</P>
<div id="example-table-colum-layout"></div>
<script type="text/javascript">
$("#example-table-colum-layout").tabulator({
height:"320px",
movableCols:true,
persistentLayout: "true",
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", width:60, sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", width:80},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
],
});
$("#example-table-colum-layout").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-colum-layout").tabulator("redraw");
});
</script>
</section>
<section>
<header>AJAX Data Loading <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#ajax">http://olifolkerd.github.io/tabulator/docs/#ajax</a></span></header>
<p>Data can be loaded into the table from a remote URL using a JSON formatted string.</p>
<p>If you always request the same URL for your data then you can set it in the <span><strong>ajaxURL</strong></span> option when you create your Tabulator</p>
<p>Click the button below to load sample data via AJAX (you will need PHP enabled on your webserver for this to work).</p>
<p><input id="ajax-trigger" type="button" value="Load Data via AJAX"></p>
<div id="example-table-ajax"></div>
<script type="text/javascript">
$("#example-table-ajax").tabulator({
height:"320px",
fitColumns:true,
ajaxURL:"/ajax_sim.php",
columns:[
{title:"Name", field:"name", sorter:"string", width:200},
{title:"Age", field:"age", sorter:"number", align:"right", formatter:"progress"},
{title:"Gender", field:"gender", sorter:"string"},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col", sorter:"string", sortable:false},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross", sorter:"boolean"},
],
});
$("#ajax-trigger").click(function(){
$("#example-table-ajax").tabulator("setData");
})
$(window).resize(function(){
$("#example-table-ajax").tabulator("redraw");
});
</script>
</section>
<section>
<header>Add / Delete Rows & Columns <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#addrow">http://olifolkerd.github.io/tabulator/docs/#addrow</a></span></header>
<p>
Tablulator allows you to add new rows and columns, delete existing rows and columns, and clear all table data with ease.
</p>
<p>
<button id="add-col">Add "Favourite Color" Column</button>
<button id="del-col">Remove "Date Of Birth" Column</button>
<button id="add-row">Add Blank Row to bottom of table</button>
<button id="del-row">Remove "Oli Bob" From the table</button>
<button id="clear">Empty the table</button>
<button id="reset">Reset the table</button>
</p>
<div id="example-table-adddel"></div>
<script type="text/javascript">
$("#add-col").click(function(){
$("#example-table-adddel").tabulator("addColumn", {title:"Favourite Color", field:"col", editable:true}, true, "height");
})
$("#del-col").click(function(){
$("#example-table-adddel").tabulator("deleteColumn", "dob");
})
$("#add-row").click(function(){
$("#example-table-adddel").tabulator("addRow");
})
$("#del-row").click(function(){
$("#example-table-adddel").tabulator("deleteRow", 1);
})
$("#clear").click(function(){
$("#example-table-adddel").tabulator("clear");
})
$("#reset").click(function(){
$("#example-table-adddel").tabulator("setData", tabledata);
})
$("#example-table-adddel").tabulator({
height:"320px",
addRowPos:"bottom",
columns:[
{title:"Name", field:"name", width:200, editable:true},
{title:"Age", field:"age", width:90, align:"right", sorter:"number", editable:true},
{title:"Gender", field:"gender", editable:true},
{title:"Height", field:"height", align:"center", width:80, editable:true},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date", editable:true},
{title:"Likes Cheese", field:"cheese", align:"center", editable:true},
],
rowEdit:function(id,data,row,index){
}
});
$("#example-table-adddel").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-adddel").tabulator("redraw");
});
</script>
</section>
<section>
<header>Movable Rows <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#movable">http://olifolkerd.github.io/tabulator/docs/#movable</a></span></header>
<p>
Using the <strong>movableRows</strong> parameter you can allow the user to move rows around the table using the handle on the left-hand side of the row.
</p>
<div id="example-table-movable-rows"></div>
<script type="text/javascript">
$("#example-table-movable-rows").tabulator({
height:"320px",
movableRows:true,
columns:[
{title:"Name", field:"name", width:200},
{title:"Age", field:"age", formatter:"progress", sorter:"number"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross"},
],
rowMoved:function(id,data,row,index){
alert("Row: " + data.name + " has been moved to position " + index)
}
});
$("#example-table-movable-rows").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-movable-rows").tabulator("redraw");
});
</script>
</section>
<section>
<header>Callbacks <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#callbacks">http://olifolkerd.github.io/tabulator/docs/#callbacks</a></span></header>
<p>Tabulator features a range of callbacks to allow you to handle user interaction.</p>
<ul>
<li><strong>Cell Click</strong> - The cell click callback is triggered when a user left clicks on a cell, it can be set on a per column basis using the <span><strong>onClick</strong></span> option in the columns data. (left click any cell in the gender column in this example)</li>
<li><strong>Row Click</strong> - The row click callback is triggered when a user clicks on a row, it can be set globally, by setting the<span><strong>rowClick</strong></span>option when you create your Tabulator. (left click any row in this example)</li>
<li><strong>Row Context Menu</strong> - The row context callback is triggered when a user right clicks on a row, it can be set globally, by setting the <span><strong>rowContext</strong></span> option when you create your Tabulator. (right click any row in this example)</li>
<li><strong>Data Loaded</strong> - The data loaded callback is triggered when a new set of data is loaded into the table, it can be set globally, by setting the <span><strong>dataLoaded</strong></span> option when you create your</li>
</ul>
<div id="example-table-callbacks"></div>
<script type="text/javascript">
$("#example-table-callbacks").tabulator({
height:"320px",
fitColumns:true,
columns:[
{title:"Name", field:"name", sorter:"string", width:150},
{title:"Age", field:"age", sorter:"number", align:"right", formatter:"progress"},
{title:"Gender", field:"gender", width:100, sorter:"string", onClick:function(e, cell, val, data){alert("cell clicked - " + val)}},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col", sorter:"string", sortable:false},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross", sorter:"boolean"},
],
rowClick:function(e, id, data, row){
alert("Row " + id + " Clicked!!!!")
},
rowContext:function(e, id, data, row){
alert("Row " + id + " Context Clicked!!!!")
},
});
$("#example-table-callbacks").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-callbacks").tabulator("redraw");
});
</script>
</script>
</section>
<section>
<header>Theming <span> - for full documentation visit <a href="http://olifolkerd.github.io/tabulator/docs/#css">http://olifolkerd.github.io/tabulator/docs/#css</a></span></header>
<p>Tabulator is styled using a full set of CSS classes, making theming of the table very simple, A full list of these can be found in the GitHub readme.md file</p>
<div id="example-table-theme"></div>
<style>
/*Theme the table*/
#example-table-theme{
background-color:#ccc;
border: 1px solid #333;
}
/*Theme the header*/
#example-table-theme .tabulator-header {
background-color:#333;
color:#fff;
}
/*Theme the rows*/
#example-table-theme .tabulator-tableHolder .tabulator-table .tabulator-row{
color:#fff;
background-color: #666;
}
#example-table-theme .tabulator-tableHolder .tabulator-table .tabulator-row:nth-child(even) {
background-color: #444;
}
</style>
<script type="text/javascript">
$("#example-table-theme").tabulator({
height:"320px",
fitColumns:true,
columns:[
{title:"Name", field:"name", sorter:"string", width:150},
{title:"Age", field:"age", sorter:"number", align:"right", formatter:"progress"},
{title:"Gender", field:"gender", width:100, sorter:"string", onClick:function(e, cell, val, data){alert("cell clicked - " + val)}},
{title:"Height", field:"height", formatter:"star", align:"center", width:100},
{title:"Favourite Color", field:"col", sorter:"string", sortable:false},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
{title:"Likes Cheese", field:"cheese", align:"center", formatter:"tickCross", sorter:"boolean"},
],
rowClick:function(e, id, data, row){
alert("Row " + id + " Clicked!!!!")
},
rowContext:function(e, id, data, row){
alert("Row " + id + " Context Clicked!!!!")
},
});
$("#example-table-theme").tabulator("setData", tabledata);
$(window).resize(function(){
$("#example-table-theme").tabulator("redraw");
});
</script>
</section>
</body>
</html>