-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomization.html
985 lines (878 loc) · 48.9 KB
/
customization.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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Griddle - React Grid Component</title>
<meta name="description" content="Griddle - React Grid component. ">
<meta name="author" content="Ryan Lanciaux">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href='//fonts.googleapis.com/css?family=Raleway:400,300,600' rel='stylesheet' type='text/css'>
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="styles/normalize.css">
<link rel="stylesheet" href="styles/skeleton.css">
<link rel="stylesheet" href="styles/site.css">
<link rel="stylesheet" href="styles/chartist.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png" />
<!-- Scripts
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react-dom.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.13.2/JSXTransformer.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="scripts/Griddle.js"></script>
<script src="scripts/GriddleWithCallback.js"></script>
<script src="scripts/fakeData.js"></script>
<script src="scripts/ChartistGraph.js"></script>
</head>
<body id="docs-page">
<header class="background-primary-dark border-bottom border-secondary">
<div class="container">
<div class="row">
<div class="eight columns">
<a href="index.html"><img src="images/griddle.png" alt="Griddle"/></a>
</div>
<div class="four columns right">
<iframe src="http://ghbtns.com/github-btn.html?user=GriddleGriddle&repo=Griddle&type=watch&count=true"
allowtransparency="true" frameborder="0" scrolling="0" width="90" height="20"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=GriddleGriddle&repo=Griddle&type=fork&count=true"
allowtransparency="true" frameborder="0" scrolling="0" width="90" height="20"></iframe>
<br />
<a href="quickstart.html" class="button border-light text-light big">Documentation</a>
</div>
</div>
</div>
</header>
<div class="container page-content">
<div class="row">
<div class="two columns">
<nav class="side">
<ul>
<li><a href="quickstart.html">Quickstart</a></li>
<li><a href="styling.html">Styling</a></li>
<li><a href="subgrids.html">Subgrids</a></li>
<li><a href="customization.html">Customization</a></li>
<li><a href="externalData.html">External Data</a></li>
<li><a href="infiniteScroll.html">Infinite Scrolling</a></li>
<li><a href="properties.html">Properties</a></li>
<li class="border-top border-lighter-grey"><a href="https://reactjsnews.com/isomorphic-javascript-with-react-node/">Isomorphic Rendering <small>(at ReactJS News)</small></a>
</ul>
</nav>
</div>
<div class="ten columns docs">
<h2 id="customization">Customization</h2>
<p><strong>Please Note: Styling is similar to customization but is in its <a href="#">own section</a> for clarity.</strong></p>
<p>Griddle comes with a number of customization options to help it fit with your project goals.</p>
<p><hr /></p>
<h3 id="default-columns">Default Columns</h3>
<p>Use the <code>columns</code> property to set the default columns in a Griddle grid. Please <a href="quickstart.html#advanced">see the quickstart guide</a> for an example.</p>
<dl>
<dt>columns</dt>
<dd><strong>array (of string)</strong> - The columns that should be displayed by default. The other columns can be chosen via the grid settings. If no columns are set, Griddle will display all columns by default.</dd>
</dl>
<h3 id="column-metadata">Column Metadata</h3>
<p>The column meta data property is used to specify column properties that are not part of the result data object. For instance, if you want to specify a displayName that is different than the property name in the result data, the <code>columnMetadata</code> property is where this would be defined.</p>
<p>Griddle parses and evaluates the following columnMetadata object properties:</p>
<dl>
<dt>columnName</dt>
<dd><strong>string (required)</strong> - this is the name of the column as it appears in the results passed into Griddle.</dd>
</dl>
<dl>
<dt>sortable</dt>
<dd><strong>bool</strong> - Determines whether or not the user can sort this column (defaults to <code>true</code>, so specify <code>false</code> to disable sort)</dd>
</dl>
<dl>
<dt>customCompareFn</dt>
<dd><strong>function</strong></dd>
<dd><strong>with 1 argument</strong> specifies a function that defines the sort order of the column data. Passed to <a href="https://lodash.com/docs#sortBy">_.sortBy</a> method, invoked with 1 argument.</dd>
<dd><strong>with 2 arguments</strong> specifies a function that defines the sort order of the column data. Passed to standard JS <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">sort</a> method, invoked ith 2 arguments. Useful, for example, wih naturalSort(a, b) from <a href="https://www.npmjs.com/package/javascript-natural-sort">javascript-natural-sort</a></dd>
</dl>
<dl>
<dt>multiSort</dt>
<dd><strong>object</strong> - allows to specify multiple sorting when sorting current column. Specified columns will be sorted after current</dd>
<code>multiSort: {
columns: ['name'],
orders: ['asc']
}</code>
</dl>
<dl>
<dt>order</dt>
<dd><strong>int</strong> - The order that this column should appear in Griddle.</dd>
</dl>
<dl>
<dt>locked</dt>
<dd><strong>bool</strong> - Determines whether or not the user can disable this column from the settings.</dd>
</dl>
<dl>
<dt>cssClassName</dt>
<dd><strong>string</strong> - The css class name to apply to this column.</dd>
</dl>
<dl>
<dt>titleStyles</dt>
<dd><strong>object</strong> - collection of styles applied to column header</dd>
</dl>
<dl>
<dt>displayName</dt>
<dd><strong>string</strong> - The display name for the column. This is used when the name in the column heading and settings should be different from the data passed in to the Griddle component.</dd>
</dl>
<dl>
<dt>customComponent</dt>
<dd><strong>React Component</strong> - The component that should be rendered instead of the standard column data. This component will still be rendered inside of a <code>TD</code> element. (more information below in the <a href="#customColumns">Custom Columns section</a>.)</dd>
</dl>
<dl>
<dt>customHeaderComponent</dt>
<dd><strong>React Component</strong> - The component that should be rendered instead of the standard header data. This component will still be rendered inside of a <code>TH</code> element. (more information below in the <a href="#customColumns">Custom Columns section</a>.)</dd>
</dl>
<dl>
<dt>customHeaderComponentProps</dt>
<dd><strong>object</strong> - An object containing additional properties that will be passed into the custom header component. (more information below in the <a href="#customColumns">Custom Columns section</a>.)</dd>
</dl>
<p>However, you are also able to pass other properties in as columnMetadata.</p>
<p><a href="#custom-columns">columnMetadata can be accessed on the <code>metadata</code> property of a Custom Column component.</a></p>
<h5 id="example-">Example:</h5>
<p>Assume we want to reverse the columns so name would be last, followed by followed by city, state, company, country and favorite number. Also we want the name column heading to read <code>Employee Name</code> instead of name.</p>
<p>Our metadata object would look something like</p>
<pre><code> {
<span class="string">"columnName"</span>: <span class="string">"name"</span>,
<span class="string">"order"</span>: 9,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>,
<span class="string">"displayName"</span>: <span class="string">"Employee Name"</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"city"</span>,
<span class="string">"order"</span>: 8,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"state"</span>,
<span class="string">"order"</span>: 7,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"country"</span>,
<span class="string">"order"</span>: 6,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"company"</span>,
<span class="string">"order"</span>: 5,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"favoriteNumber"</span>,
<span class="string">"order"</span>: 4,
<span class="string">"locked"</span>: <span class="literal">false</span>,
<span class="string">"visible"</span>: <span class="literal">true</span>,
<span class="string">"displayName"</span>: <span class="string">"Favorite Number"</span>,
<span class="string">"sortable"</span>: <span class="literal">false</span>
}</code></pre>
<p>We would then load Griddle as follows:</p>
<pre><code>React.render(
<span class="xml"><span class="tag"><<span class="title">Griddle</span> <span class="attribute">results</span>=<span class="value">{fakeData}</span> <span class="attribute">columnMetadata</span>=<span class="value">{exampleMetadata}</span> <span class="attribute">showFilter</span>=<span class="value">{true}</span>
<span class="attribute">showSettings</span>=<span class="value">{true}</span> <span class="attribute">columns</span>=<span class="value">{["name",</span> "<span class="attribute">city</span>", "<span class="attribute">state</span>", "<span class="attribute">country</span>"]}/></span>,
document.getElementById('griddle-metadata')</span></code></pre>
<div id="griddle-metadata"></div>
<script type="text/jsx">
var exampleMetadata = [
{
"columnName": "id",
"order": 1,
"locked": false,
"visible": false,
"displayName": "ID"
},
{
"columnName": "name",
"order": 9,
"locked": false,
"visible": true,
"displayName": "Employee Name"
},
{
"columnName": "city",
"order": 8,
"locked": false,
},
{
"columnName": "state",
"order": 7,
"locked": false,
"visible": true
},
{
"columnName": "country",
"order": 6,
"locked": false,
"visible": true
},
{
"columnName": "company",
"order": 5,
"locked": false,
"visible": true
},
{
"columnName": "favoriteNumber",
"order": 4,
"locked": false,
"visible": true,
"displayName": "Favorite Number"
}
];
ReactDOM.render(
<Griddle results={fakeData} columnMetadata={exampleMetadata} tableClassName="table" showFilter={true} showSettings={true} columns={["name", "city", "state", "country"]}/>, document.getElementById('griddle-metadata')
);
</script>
<p><a name="customColumns"></a></p>
<h3 id="custom-columns">Custom Columns</h3>
<p>Custom column components are defined in the <a href="#">Column Metadata object</a>. The components are passed <strong>data</strong>, <strong>rowData</strong>, <strong>metadata</strong> properties.</p>
<dl>
<dt>data</dt>
<dd><strong>object</strong> - the data that would normally be rendered in the column.</dd>
</dl>
<dl>
<dt>rowData</dt>
<dd><strong>object</strong> - the data for all items in the same row</dd>
</dl>
<dl>
<dt>metadata</dt>
<dd><strong>object</strong> - The columnMetadata object</dd>
</dl>
<h5 id="example-">Example:</h5>
<p>We are going to make the body of one of the columns a link. This link will use data from another column to determine the href.</p>
<p>Assume we have the following data for our grid:</p>
<pre><code>var someData = [
{
<span class="string">"id"</span>: <span class="number">0</span>,
<span class="string">"name"</span>: <span class="string">"Mayer Leonard"</span>,
<span class="string">"city"</span>: <span class="string">"Kapowsin"</span>,
<span class="string">"state"</span>: <span class="string">"Hawaii"</span>,
<span class="string">"country"</span>: <span class="string">"United Kingdom"</span>,
<span class="string">"company"</span>: <span class="string">"Ovolo"</span>,
<span class="string">"favoriteNumber"</span>: <span class="number">7</span>
},
{
<span class="string">"id"</span>: <span class="number">1</span>,
<span class="string">"name"</span>: <span class="string">"Koch Becker"</span>,
<span class="string">"city"</span>: <span class="string">"Johnsonburg"</span>,
<span class="string">"state"</span>: <span class="string">"New Jersey"</span>,
<span class="string">"country"</span>: <span class="string">"Madagascar"</span>,
<span class="string">"company"</span>: <span class="string">"Eventage"</span>,
<span class="string">"favoriteNumber"</span>: <span class="number">2</span>
},
<span class="keyword">...</span>
];</code></pre>
<p>We want the <strong>name</strong> column to be a link to <code>/speakers/state/name</code> (where state and name are pulled in from the data). We can define a customComponent to be rendered as follows:</p>
<pre><code><span class="keyword">var</span> LinkComponent = React.createClass({
render: <span class="keyword">function</span>(){
url =<span class="string">"speakers/"</span> + <span class="keyword">this</span>.props.rowData.state + <span class="string">"/"</span> + <span class="keyword">this</span>.props.data;
<span class="keyword">return</span> <span class="xml"><span class="tag"><<span class="title">a</span> <span class="attribute">href</span>=<span class="value">{url}</span>></span>{this.props.data}<span class="tag"></<span class="title">a</span>></span>
}
});</span></code></pre>
<p>Additionally, we want the city and state column headers to be highlighted a specific color and have a filter by column input. We can define a custom header component as:</p>
<pre><code><span class="keyword">var</span> HeaderComponent = React.createClass({
textOnClick: <span class="keyword">function</span>(e) {
e.stopPropagation();
},
filterText: <span class="keyword">function</span>(e) {
<span class="keyword">this</span>.props.filterByColumn(e.target.value, <span class="keyword">this</span>.props.columnName)
},
render: <span class="keyword">function</span>(){
<span class="keyword">return</span> (
<span class="xml"><span class="tag"><<span class="title">span</span>></span>
<span class="tag"><<span class="title">div</span>></span><span class="tag"><<span class="title">strong</span> <span class="attribute">style</span>=<span class="value">{{color:</span> <span class="attribute">this.props.color</span>}}></span>{this.props.displayName}<span class="tag"></<span class="title">strong</span>></span><span class="tag"></<span class="title">div</span>></span>
<span class="tag"><<span class="title">input</span> <span class="attribute">type</span>=<span class="value">'text'</span> <span class="attribute">onChange</span>=<span class="value">{this.filterText}</span> <span class="attribute">onClick</span>=<span class="value">{this.textOnClick}</span> /></span>
<span class="tag"></<span class="title">span</span>></span>
);
}
});</span></code></pre>
<p><small>Please note: filterByColumn is a method that is passed as a prop to any customHeaderComponent.</small></p>
<p>From there, we will set the customComponent value in the <strong>name</strong> columnMetadata object to this LinkComponent. We're also going to update <strong>state</strong> and <strong>city</strong>'s <code>customHeaderComponent</code> and <code>customHeaderComponentProps</code>.</p>
<pre><code>var columnMeta = [
{
<span class="keyword">...</span>
<span class="string">"columnName"</span>: <span class="string">"name"</span>,
<span class="string">"order"</span>: <span class="number">1</span>,
<span class="string">"locked"</span>: false,
<span class="string">"visible"</span>: true,
<span class="string">"customComponent"</span>: LinkComponent
},
{
<span class="keyword">...</span>
<span class="string">"columnName"</span>: <span class="string">"city"</span>,
<span class="string">"customHeaderComponent"</span>: HeaderComponent,
<span class="string">"customHeaderComponentProps"</span>: { color: <span class="string">'red'</span> }
},
{
<span class="keyword">...</span>
<span class="string">"columnName"</span>: <span class="string">"state"</span>,
<span class="string">"customHeaderComponent"</span>: HeaderComponent,
<span class="string">"customHeaderComponentProps"</span>: { color: <span class="string">'blue'</span> }
},
<span class="keyword">...</span>
];</code></pre>
<p>Now, when Griddle is rendered with this columnMetadata, it should write the link as expected.</p>
<pre><code>React.render(<span class="xml"><span class="tag"><<span class="title">Griddle</span> <span class="attribute">data</span>=<span class="value">{someData}</span> <span class="attribute">columnMetadata</span>=<span class="value">{columnMeta}</span> /></span>,
document.getElementById('something'));</span></code></pre>
<div id="customLink"></div>
<script type="text/jsx">
/** @jsx React.DOM */
var LinkComponent = React.createClass({
render: function(){
url ="#speakers/" + this.props.rowData.state + "/" + this.props.data;
return <a href={url}>{this.props.data}</a>
}
});
var HeaderComponent = React.createClass({
textOnClick: function(e) {
e.stopPropagation();
},
filterText: function(e) {
this.props.filterByColumn(e.target.value, this.props.columnName)
},
render: function(){
return (
<span>
<div><strong style={{color: this.props.color}}>{this.props.displayName}</strong></div>
<input type='text' onChange={this.filterText} onClick={this.textOnClick} />
</span>
);
}
});
var customColumnMetadata = [
{
"columnName": "id",
"order": 1,
"locked": false,
"visible": true
},
{
"columnName": "name",
"order": 2,
"locked": false,
"visible": true,
"customComponent": LinkComponent
},
{
"columnName": "city",
"order": 3,
"locked": false,
"visible": true,
"customHeaderComponent": HeaderComponent,
"customHeaderComponentProps": { color: 'red' }
},
{
"columnName": "state",
"order": 4,
"locked": false,
"visible": true,
"customHeaderComponent": HeaderComponent,
"customHeaderComponentProps": { color: 'blue' }
},
{
"columnName": "country",
"order": 5,
"locked": false,
"visible": true
},
{
"columnName": "company",
"order": 6,
"locked": false,
"visible": true
},
{
"columnName": "favoriteNumber",
"order": 7,
"locked": false,
"visible": true
}
];
ReactDOM.render(
<Griddle results={fakeData} columnMetadata={customColumnMetadata} columns={["name", "city", "state", "country"]}/>, document.getElementById('customLink')
);
</script>
<hr />
<h3 id="custom-sorting">Custom sorting</h3>
<h5 id="example-">Example:</h5>
<p>In this example we are going to sort <code>Employee Name</code> column by last name, followed by first name:</p>
<pre><code>var exampleMetadata = [
{
<span class="string">"columnName"</span>: <span class="string">"id"</span>,
<span class="string">"order"</span>: <span class="number">1</span>,
<span class="string">"locked"</span>: false,
<span class="string">"visible"</span>: false,
<span class="string">"displayName"</span>: <span class="string">"ID"</span>
},
{
<span class="string">"columnName"</span>: <span class="string">"name"</span>,
<span class="string">"order"</span>: <span class="number">9</span>,
<span class="string">"locked"</span>: false,
<span class="string">"visible"</span>: true,
<span class="string">"displayName"</span>: <span class="string">"Employee Name"</span>,
<span class="string">"compare"</span>: <span class="keyword">function</span>(name) {
var a = name.split(<span class="string">" "</span>);
<span class="keyword">return</span> a[<span class="number">1</span>] + <span class="string">" "</span> + a[<span class="number">0</span>];
}
},
<span class="keyword">...</span>
]</code></pre>
<p>Then, like in first example, but specify initialSort column:</p>
<pre><code>React.render(
<span class="xml"><span class="tag"><<span class="title">Griddle</span> <span class="attribute">results</span>=<span class="value">{fakeData}</span> <span class="attribute">columnMetadata</span>=<span class="value">{exampleMetadata}</span> <span class="attribute">showFilter</span>=<span class="value">{true}</span>
<span class="attribute">showSettings</span>=<span class="value">{true}</span> <span class="attribute">columns</span>=<span class="value">{["name",</span> "<span class="attribute">city</span>", "<span class="attribute">state</span>", "<span class="attribute">country</span>"]} <span class="attribute">initialSort</span>=<span class="value">"name"</span>/></span>,
document.getElementById('griddle-metadata')</span></code></pre>
<div id="griddle-sorting"></div>
<script type="text/jsx">
var exampleMetadata = [
{
"columnName": "id",
"order": 1,
"locked": false,
"visible": false,
"displayName": "ID"
},
{
"columnName": "name",
"order": 9,
"locked": false,
"visible": true,
"displayName": "Employee Name",
"compare": function(name) {
var a = name.split(" ");
return a[1] + " " + a[0];
}
},
{
"columnName": "city",
"order": 8,
"locked": false,
},
{
"columnName": "state",
"order": 7,
"locked": false,
"visible": true
},
{
"columnName": "country",
"order": 6,
"locked": false,
"visible": true
},
{
"columnName": "company",
"order": 5,
"locked": false,
"visible": true
},
{
"columnName": "favoriteNumber",
"order": 4,
"locked": false,
"visible": true,
"displayName": "Favorite Number"
}
];
ReactDOM.render(
<Griddle results={fakeData} columnMetadata={exampleMetadata} tableClassName="table" showFilter={true} showSettings={true} columns={["name", "city", "state", "country"]} initialSort="name"/>, document.getElementById('griddle-sorting')
);
</script>
<hr />
<h3 id="row-metadata">Row Metadata</h3>
<dl>
<dt>bodyCssClassName</dt>
<dd><strong>function or string</strong> - If you supply a string, that class is applied to all rows. If you supply a function, the rows data is supplied to that function as the first argument and you are expected to return the css class name. This is useful if you want to style a row based on the rows data.</dd>
</dl>
<h5 id="example-">Example:</h5>
<pre><code class="lang-javascript"><span class="keyword">var</span> rowMetadata = {
<span class="string">"bodyCssClassName"</span>: <span class="keyword">function</span>(rowData) {
<span class="keyword">if</span> (rowData.action === <span class="string">"added"</span>) {
<span class="keyword">return</span> <span class="string">"green-row"</span>;
} <span class="keyword">else</span> <span class="keyword">if</span> (rowData.action === <span class="string">"removed"</span>) {
<span class="keyword">return</span> <span class="string">"red-row"</span>;
} <span class="keyword">else</span> <span class="keyword">if</span> (rowData.action === <span class="string">"transfer"</span>) {
<span class="keyword">return</span> <span class="string">"blue-row"</span>;
}
<span class="keyword">return</span> <span class="string">"default-row"</span>;
}
};
<span class="keyword">return</span> (
<span class="xml"><span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"griddle-container"</span>></span>
<span class="tag"><<span class="title">Griddle</span> <span class="attribute">results</span>=<span class="value">{this.state.rows}</span> <span class="attribute">rowMetadata</span>=<span class="value">{rowMetadata}</span> /></span>
<span class="tag"></<span class="title">div</span>></span>
)</span></code></pre>
<h3 id="custom-row-format">Custom Row Format</h3>
<p>Sometimes you may want to display grid data in a format other than a grid but still have pagination, filtering, etc. This type of formatting can be accomplished with the custom row format properties. To use custom row formatting, the <strong>useCustomRowComponent</strong> and the <strong>customRowComponent</strong> properties will need to be set.</p>
<dl>
<dt>useCustomRowComponent</dt>
<dd><strong>bool</strong> - determines if custom row formats are applied</dd>
</dl>
<dl>
<dt>customRowComponent</dt>
<dd><strong>Component</strong> - the component to render in place of a grid row. This component receives a property named <strong>data</strong></dd>
</dl>
<dl>
<dt>customRowComponentClassName</dt>
<dd><strong>string</strong> - the CSS class name to apply to the format component.</dd>
</dl>
<dl>
<dt>enableToggleCustom</dt>
<dd><strong>bool</strong> - whether or not the user should be able to toggle between custom format and grid format.</dd>
</dl>
<h5 id="example-">Example:</h5>
<p>We are going to render our grid as a series of cards, keeping the pagination and filtering from Griddle in tact. Assume we are using the same data in the custom column example. We will need to create a custom component as follows:</p>
<pre><code><span class="keyword">var</span> OtherComponent = React.createClass({
getDefaultProps: <span class="keyword">function</span>(){
<span class="keyword">return</span> { <span class="string">"data"</span>: {} };
},
render: <span class="keyword">function</span>(){
<span class="keyword">return</span> (<span class="xml"><span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"custom-row-card"</span>></span>
<span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"name"</span>></span><span class="tag"><<span class="title">strong</span>></span>{this.props.data.name}<span class="tag"></<span class="title">strong</span>></span><span class="tag"><<span class="title">small</span>></span>{this.props.data.company}<span class="tag"></<span class="title">small</span>></span><span class="tag"></<span class="title">div</span>></span>
<span class="tag"><<span class="title">div</span>></span>{this.props.data.city}<span class="tag"></<span class="title">div</span>></span>
<span class="tag"><<span class="title">div</span>></span>{this.props.data.state}, {this.props.data.country}<span class="tag"></<span class="title">div</span>></span>
<span class="tag"></<span class="title">div</span>></span>);
}
});</span></code></pre>
<p>From there, Griddle can be rendered with the useCustomRowComponent and customRowComponent properties:</p>
<div id='custom-row'></div>
<script type="text/jsx">
/** @jsx React.DOM */
var OtherComponent = React.createClass({
getDefaultProps: function(){
return { "data": {} };
},
render: function(){
return (<div className="custom-row-card">
<div className="name"><strong className="text-primary">{this.props.data.name}</strong><small className="text-primary-light">{this.props.data.company}</small></div>
<div>{this.props.data.city}</div>
<div>{this.props.data.state}, {this.props.data.country}</div>
</div>);
}
});
ReactDOM.render(
<Griddle results={fakeData} useCustomRowComponent={true} customRowComponent={OtherComponent} customRowComponentClassName={"custom-row"} enableToggleCustom={true} showSettings={true} showFilter={true}/>,
document.getElementById('custom-row')
);
</script>
<hr />
<h3 id="custom-grid-format">Custom Grid Format</h3>
<p>In some cases, it may be ideal to use Griddle but display a global format other than a grid or series of rows. Assume we have an object containing temperature data for years and we want to display this data with a trend line chart. This is possible with a custom grid format component. To use custom grid formatting the <strong>useCustomGridComponent</strong> and <strong>customGridComponent</strong> properties need to be set.</p>
<dl>
<dt>useCustomGridComponent</dt>
<dd><strong>bool</strong> - determines if custom row formats are applied</dd>
</dl>
<dl>
<dt>customGridComponent</dt>
<dd><strong>Component</strong> - the component to render in place of a grid row. This component receives a property named <strong>data</strong></dd>
</dl>
<dl>
<dt>customGridComponentClassName</dt>
<dd><strong>string</strong> - the CSS class name to apply to the format component.</dd>
</dl>
<dl>
<dt>enableToggleCustom</dt>
<dd><strong>bool</strong> - whether or not the user should be able to toggle between custom format and grid format.</dd>
</dl>
<h5 id="example-">Example:</h5>
<p>As stated above we are going to render a visualization of temperature data rather than a chart. To start off we need to create a visualization component that uses a data property to obtain its values (the following example uses the awesome <a href="http://gionkunz.github.io/chartist-js/">chartist library</a> and <a href="https://fraserxu.me/react-chartist/">accompanying react component</a>):</p>
<pre><code><span class="title">var</span> <span class="type">TestLineChart</span> = <span class="type">React</span>.createClass({
render: function(){
var simpleLineChartData = {
labels: _.keys(this.props.<span class="typedef"><span class="keyword">data</span>[0]),</span>
series: []
};
_.each(this.props.<span class="typedef"><span class="keyword">data</span>, function<span class="container">(<span class="title">item</span>)</span><span class="container">{
<span class="title">simpleLineChartData</span>.<span class="title">series</span>.<span class="title">push</span>(<span class="title">_</span>.<span class="title">values</span>(<span class="title">item</span>));
}</span>);</span>
return <<span class="type">ChartistGraph</span> <span class="typedef"><span class="keyword">data</span>=<span class="container">{<span class="title">simpleLineChartData</span>}</span> <span class="keyword">type</span>=<span class="container">{'<span class="type">Line</span>'}</span> /></span>
}
});</code></pre>
<div id="grid-chart"></div>
<script type="text/jsx">
var data = [
{
"January": 35,
"February": 40,
"March": 47,
"April": 52,
"May": 73,
"June": 75
},
{
"January": 21,
"February": 30,
"March": 46,
"April": 53,
"May": 66,
"June": 81
},
{
"January": 28,
"February": 28,
"March": 49,
"April": 49,
"May": 67,
"June": 80
}
];
var TestLineChart = React.createClass({
render: function(){
var type = this.props.type || 'Line'
var simpleLineChartData = {
labels: _.keys(this.props.data[0]),
series: []
};
_.each(this.props.data, function(item){
simpleLineChartData.series.push(_.values(item));
});
return <ChartistGraph data={simpleLineChartData} type={type} />
}
});
ReactDOM.render(<Griddle enableToggleCustom={true} showSettings={true} results={data} useCustomGridComponent={true} customGridComponent={TestLineChart} tableClassName="table" gridMetadata={{type: 'Bar'}}/>, document.getElementById('grid-chart'));
</script>
<hr />
<h3 id="custom-filtering-and-filter-component">Custom Filtering and Filter Component</h3>
<p>Griddle supports custom filtering and custom filter components. In order to use a custom filter function set the property <code>useCustomFilterer</code> to true and pass in a function to the <code>customFilterer</code> property. To use a custom filter component set <code>useCustomFilterComponent</code> to true and pass a component to <code>customFilterComponent</code>.</p>
<h5 id="example-">Example:</h5>
<p>This example shows how to make a custom filter component with a custom filter function that does a case-insensitive search through the items. The component must call <code>this.props.changeFilter(val)</code> when the filter should be updated. In the example below we pass a string but any variable type can be used as long as the filter function is expecting it, for example an advanced query could be passed in using an object. The filter function signature takes the items to be filtered and the query to filter them by.</p>
<pre><code class="lang-javascript"> squish = require(<span class="string">'object-squish'</span>);
<span class="keyword">var</span> customFilterFunction = <span class="keyword">function</span>(items, query) {
<span class="keyword">return</span> _.filter(items, (item) => {
<span class="keyword">var</span> flat = squish(item);
<span class="keyword">for</span> (<span class="keyword">var</span> key <span class="keyword">in</span> flat) {
<span class="keyword">if</span> (String(flat[key]).toLowerCase().indexOf(query.toLowerCase()) >= <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">true</span>;
};
<span class="keyword">return</span> <span class="literal">false</span>;
});
};
<span class="keyword">var</span> customFilterComponent = React.createClass({
getDefaultProps: <span class="keyword">function</span>() {
<span class="keyword">return</span> {
<span class="string">"query"</span>: <span class="string">""</span>
}
},
searchChange: <span class="keyword">function</span>(event) {
<span class="keyword">this</span>.props.query = event.target.value;
<span class="keyword">this</span>.props.changeFilter(<span class="keyword">this</span>.props.query);
},
render: <span class="keyword">function</span>() {
<span class="keyword">return</span> (
<span class="xml"><span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"filter-container"</span>></span>
<span class="tag"><<span class="title">input</span> <span class="attribute">type</span>=<span class="value">"text"</span>
<span class="attribute">name</span>=<span class="value">"search"</span>
<span class="attribute">placeholder</span>=<span class="value">"Search..."</span>
<span class="attribute">onChange</span>=<span class="value">{this.searchChange}</span> /></span>
<span class="tag"></<span class="title">div</span>></span>
)
}
});</span></code></pre>
<p>Then initialize Griddle:</p>
<pre><code>React.render(
<span class="xml"><span class="tag"><<span class="title">Griddle</span> <span class="attribute">results</span>=<span class="value">{fakeData}</span> <span class="attribute">showFilter</span>=<span class="value">{true}</span>
<span class="attribute">useCustomFilterer</span>=<span class="value">{true}</span> <span class="attribute">customFilterer</span>=<span class="value">{customFilterFunction}</span>
<span class="attribute">useCustomFilterComponent</span>=<span class="value">{true}</span> <span class="attribute">customFilterComponent</span>=<span class="value">{customFilterComponent}</span>/></span>,
document.getElementById('griddle-metadata')</span></code></pre>
<hr />
<h3 id="custom-paging-component">Custom Paging Component</h3>
<p>If you want to customize the paging component, just set the property 'useCustomPagerComponent' to true and pass in another component as property named 'customPagerComponent'. The example component below shows 11 buttons (5 previous, current, 5 next):</p>
<dl>
<dt>useCustomPagerComponent</dt>
<dd><strong>bool</strong> - Use custom pagination component rather than default pager. default: false</dd>
</dl>
<dl>
<dt>customPagerComponent</dt>
<dd><strong>object</strong> - The custom pagination component. default: {}</dd>
</dl>
<dl>
<dt>customPagerComponentOptions</dt>
<dd><strong>object</strong> - Any options to be passed to the custom pagination component. default: {}</dd>
</dl>
<h5 id="example">Example</h5>
<pre><code class="lang-javascript"><span class="keyword">var</span> OtherPager = React.createClass({
getDefaultProps: <span class="keyword">function</span>(){
<span class="keyword">return</span>{
<span class="string">"maxPage"</span>: <span class="number">0</span>,
<span class="string">"nextText"</span>: <span class="string">""</span>,
<span class="string">"previousText"</span>: <span class="string">""</span>,
<span class="string">"currentPage"</span>: <span class="number">0</span>,
}
},
pageChange: <span class="keyword">function</span>(event){
<span class="keyword">this</span>.props.setPage(parseInt(event.target.getAttribute(<span class="string">"data-value"</span>)));
},
render: <span class="keyword">function</span>(){
<span class="keyword">var</span> previous = <span class="string">""</span>;
<span class="keyword">var</span> next = <span class="string">""</span>;
<span class="keyword">if</span>(<span class="keyword">this</span>.props.currentPage > <span class="number">0</span>){
previous = <span class="xml"><span class="tag"><<span class="title">span</span> <span class="attribute">onClick</span>=<span class="value">{this.props.previous}</span> <span class="attribute">className</span>=<span class="value">"previous"</span>></span><span class="tag"><<span class="title">i</span> <span class="attribute">className</span>=<span class="value">"glyphicon glyphicon-arrow-left"</span>></span><span class="tag"></<span class="title">i</span>></span>{this.props.previousText}<span class="tag"></<span class="title">span</span>></span>
}
if(this.props.currentPage != (this.props.maxPage -1)){
next = <span class="tag"><<span class="title">span</span> <span class="attribute">onClick</span>=<span class="value">{this.props.next}</span> <span class="attribute">className</span>=<span class="value">"next"</span>></span>{this.props.nextText}<span class="tag"><<span class="title">i</span> <span class="attribute">className</span>=<span class="value">"glyphicon glyphicon-arrow-right"</span>></span><span class="tag"></<span class="title">i</span>></span><span class="tag"></<span class="title">span</span>></span>
}
var options = [];
var startIndex = Math.max(this.props.currentPage - 5, 0);
var endIndex = Math.min(startIndex + 11, this.props.maxPage);
if (this.props.maxPage >= 11 && (endIndex - startIndex) <span class="tag"><<span class="title">=</span> <span class="attribute">10</span>) {
<span class="attribute">startIndex</span> = <span class="attribute">endIndex</span> <span class="attribute">-</span> <span class="attribute">11</span>;
}
<span class="attribute">for</span>(<span class="attribute">var</span> <span class="attribute">i</span> = <span class="attribute">startIndex</span>; <span class="attribute">i</span> < <span class="attribute">endIndex</span> ; <span class="attribute">i</span>++){
<span class="attribute">var</span> <span class="attribute">selected</span> = <span class="attribute">this.props.currentPage</span> =<span class="value">=</span> <span class="attribute">i</span> ? "<span class="attribute">current-page-selected</span>" <span class="attribute">:</span> "";
<span class="attribute">options.push</span>(<<span class="attribute">button</span> <span class="attribute">className</span>=<span class="value">{selected}</span> <span class="attribute">data-value</span>=<span class="value">{i}</span> <span class="attribute">onClick</span>=<span class="value">{this.pageChange}</span>></span>{i + 1}<span class="tag"></<span class="title">button</span>></span>);
}
return (
<span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"row custom-pager"</span>></span>
<span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"col-xs-4"</span>></span>{previous}<span class="tag"></<span class="title">div</span>></span>
<span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"col-xs-4 center pages"</span>></span>
{options}
<span class="tag"></<span class="title">div</span>></span>
<span class="tag"><<span class="title">div</span> <span class="attribute">className</span>=<span class="value">"col-xs-4 right"</span>></span>{next}<span class="tag"></<span class="title">div</span>></span>
<span class="tag"></<span class="title">div</span>></span>
)
}
});</span></code></pre>
<p>Then initialize your component as follows:</p>
<pre><code><span class="tag"><<span class="title">Griddle</span> <span class="attribute">results</span>=<span class="value">{fakeData}</span> <span class="attribute">tableClassName</span>=<span class="value">"table"</span> <span class="attribute">useCustomRowComponent</span>=<span class="value">"true"</span>
<span class="attribute">customRowComponent</span>=<span class="value">{OtherComponent}</span> <span class="attribute">useCustomPagerComponent</span>=<span class="value">"true"</span> <span class="attribute">customPagerComponent</span>=<span class="value">{OtherPager}</span> /></span></code></pre>
<div id="custom-paging"></div>
<script type="text/jsx">
var OtherPager = React.createClass({
getDefaultProps: function(){
return{
"maxPage": 0,
"nextText": "",
"previousText": "",
"currentPage": 0,
}
},
pageChange: function(event){
this.props.setPage(parseInt(event.target.getAttribute("data-value")));
},
render: function(){
var previous = "";
var next = "";
if(this.props.currentPage > 0){
previous = <span onClick={this.props.previous} className="previous"><i className="glyphicon glyphicon-arrow-left"></i>{this.props.previousText}</span>
}
if(this.props.currentPage != (this.props.maxPage -1)){
next = <span onClick={this.props.next} className="next">{this.props.nextText}<i className="glyphicon glyphicon-arrow-right"></i></span>
}
var options = [];
var startIndex = Math.max(this.props.currentPage - 5, 0);
var endIndex = Math.min(startIndex + 11, this.props.maxPage);
if (this.props.maxPage >= 11 && (endIndex - startIndex) <= 10) {
startIndex = endIndex - 11;
}
for(var i = startIndex; i < endIndex ; i++){
var selected = this.props.currentPage == i ? "current-page-selected" : "";
options.push(<button className={selected} data-value={i} onClick={this.pageChange}>{i + 1}</button>);
}
return (
<div className="row custom-pager">
<div className="one column">{previous}</div>
<div className="ten columns">
{options}
</div>
<div className="one column">{next}</div>
</div>
)
}
});
ReactDOM.render(<Griddle results={fakeData} tableClassName="table" useCustomRowComponent={true}
customRowComponent={OtherComponent} useCustomPagerComponent={true} customPagerComponent={OtherPager} />, document.getElementById("custom-paging"));
</script>
<hr />
<h3 id="no-data">No Data</h3>
<p>Griddle will, by default, show a message if there is no data in the result set. There are two ways that it can be customized though.</p>
<h4 id="basic-nodata-message">Basic NoData message</h4>
<p>The first way to customize what Griddle does when there is no data is setting the <code>noDataMessage</code> property.</p>
<dl>
<dt>noDataMessage</dt>
<dd><strong>string</strong> - The message that will be displayed when there is no data</dd>
</dl>
<dl>
<dt>noDataClassName</dt>
<dd><strong>string</strong> - The CSS class name to apply to the grid when no data is available <span class="text-light-grey">Default: griddle-nodata</span></dd>
</dl>
<h5 id="example-">Example:</h5>
<pre><code><span class="tag"><<span class="title">Griddle</span> <span class="attribute">noDataMessage</span>=<span class="value">{"No</span> <span class="attribute">data</span> <span class="attribute">could</span> <span class="attribute">be</span> <span class="attribute">found.</span>"} /></span></code></pre>
<div id="griddle-nodata-basic"></div>
<script type="text/jsx">
ReactDOM.render(<Griddle noDataMessage={"No data could be found."} />, document.getElementById("griddle-nodata-basic"));
</script>
<hr />
<h4 id="nodata-component">NoData Component</h4>
<p>Outside of the NoData message, Griddle can take a <code>customNoDataComponent</code> that will be displayed when there are no records.</p>
<dl>
<dt>customNoDataComponent</dt>
<dd><strong>object</strong> - The component that will be displayed when there is no data</dd>
</dl>
<h5 id="example-">Example:</h5>
<pre><code><span class="keyword">var</span> NoDataComponent = React.createClass({
render: <span class="keyword">function</span>(){
<span class="keyword">return</span> (<span class="xml"><span class="tag"><<span class="title">div</span>></span>
<span class="tag"><<span class="title">h1</span>></span>No data is available<span class="tag"></<span class="title">h1</span>></span>
<span class="tag"><<span class="title">a</span> <span class="attribute">href</span>=<span class="value">"http://www.google.com"</span>></span>You can google for more data<span class="tag"></<span class="title">a</span>></span>
<span class="tag"></<span class="title">div</span>></span>
);
}
});
React.render(<span class="tag"><<span class="title">Griddle</span> <span class="attribute">customNoDataComponent</span>=<span class="value">{NoDataComponent}</span> /></span>, document.getElementById("some-id"));</span></code></pre>
<div id="griddle-nodata-component"></div>
<script type="text/jsx">
var NoDataComponent = React.createClass({
render: function(){
return (<div className="noDataComponent">
<h1>No data is available</h1>
<a href="http://www.google.com">You can google for more data</a>
</div>
);
}
});
ReactDOM.render(<Griddle customNoDataComponent={NoDataComponent} />, document.getElementById("griddle-nodata-component"));
</script>
<hr />
<h3 id="custom-icons">Custom Icons</h3>
<p>Please see the <a href="styling.html">styling section</a> for custom icons.</p>
</div>
</div>
</div>
<div class="order-primary content-section background-darker-grey text-light-grey" id="about">
<div class="container">
<div class="row">
<div class="ten columns offset-by-two">
<p>Griddle is a project maintained by <a href="http://twitter.com/ryanlanciaux">Ryan Lanciaux</a> and <a href="http://www.twitter.com/joellanciaux">Joel Lanciaux</a> in collaboration with all of <a href="https://github.com/GriddleGriddle/Griddle/graphs/contributors">the awesome contributors!</a></p>
<small>
© 2015 <a href="http://www.twitter.com/ryanlanciaux">Ryan Lanciaux</a> | <a href="https://www.github.com/DynamicTyped">DynamicTyped</a>
</small>
<br />
<small>
Example data has been generated with <a href="http://json-generator.com">json-generator.com</a>. Any data that resembles real people, places, companies, etc. is coincidence.
</small>
</div>
</div>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58716212-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>