File tree Expand file tree Collapse file tree 7 files changed +92
-4
lines changed
react-bootstrap-table2-example Expand file tree Collapse file tree 7 files changed +92
-4
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ import BootstrapTable from 'react-bootstrap-table-next' ;
4+ import Code from 'components/common/code-block' ;
5+ import { productsGenerator } from 'utils/common' ;
6+
7+ const products = productsGenerator ( 87 ) ;
8+
9+ const columns = [ {
10+ dataField : 'id' ,
11+ text : 'Product ID'
12+ } , {
13+ dataField : 'name' ,
14+ text : 'Product Name'
15+ } , {
16+ dataField : 'price' ,
17+ text : 'Product Price'
18+ } ] ;
19+
20+ const sourceCode = `\
21+ import BootstrapTable from 'react-bootstrap-table-next';
22+
23+ const columns = [{
24+ dataField: 'id',
25+ text: 'Product ID'
26+ }, {
27+ dataField: 'name',
28+ text: 'Product Name'
29+ }, {
30+ dataField: 'price',
31+ text: 'Product Price'
32+ }];
33+
34+ <BootstrapTable sticky keyField="id" data={ products } columns={ columns } />
35+ ` ;
36+
37+ export default ( ) => (
38+ < div >
39+ < BootstrapTable sticky keyField = "id" data = { products } columns = { columns } />
40+
41+ < Code > { sourceCode } </ Code >
42+ </ div >
43+ ) ;
Original file line number Diff line number Diff line change @@ -168,6 +168,9 @@ import CustomCSV from 'examples/csv/custom-csv';
168168import EmptyTableOverlay from 'examples/loading-overlay/empty-table-overlay' ;
169169import TableOverlay from 'examples/loading-overlay/table-overlay' ;
170170
171+ // sticky header table
172+ import StickyHeaderTable from 'examples/sticky-header/default' ;
173+
171174// remote
172175import RemoteSort from 'examples/remote/remote-sort' ;
173176import RemoteFilter from 'examples/remote/remote-filter' ;
@@ -362,6 +365,10 @@ storiesOf('Export CSV', module)
362365 . add ( 'Export Custom Data' , ( ) => < ExportCustomData /> )
363366 . add ( 'Custom CSV' , ( ) => < CustomCSV /> ) ;
364367
368+ storiesOf ( 'Sticky header' , module )
369+ . addDecorator ( bootstrapStyle ( ) )
370+ . add ( 'Default sticky header' , ( ) => < StickyHeaderTable /> ) ;
371+
365372storiesOf ( 'EmptyTableOverlay' , module )
366373 . addDecorator ( bootstrapStyle ( ) )
367374 . add ( 'Empty Table Overlay' , ( ) => < EmptyTableOverlay /> )
Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
5757 rowEvents,
5858 selectRow,
5959 expandRow,
60- cellEdit
60+ cellEdit,
61+ sticky
6162 } = this . props ;
6263
6364 const tableWrapperClass = cs ( 'react-bootstrap-table' , wrapperClasses ) ;
@@ -66,7 +67,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
6667 'table-striped' : striped ,
6768 'table-hover' : hover ,
6869 'table-bordered' : bordered ,
69- 'table-condensed' : condensed
70+ 'table-condensed' : condensed ,
71+ 'table-sticky' : sticky
7072 } , classes ) ;
7173
7274 const tableCaption = ( caption && < Caption > { caption } </ Caption > ) ;
@@ -118,6 +120,7 @@ BootstrapTable.propTypes = {
118120 noDataIndication : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . func ] ) ,
119121 striped : PropTypes . bool ,
120122 bordered : PropTypes . bool ,
123+ sticky : PropTypes . bool ,
121124 hover : PropTypes . bool ,
122125 tabIndexCell : PropTypes . bool ,
123126 id : PropTypes . string ,
@@ -190,6 +193,7 @@ BootstrapTable.defaultProps = {
190193 remote : false ,
191194 striped : false ,
192195 bordered : true ,
196+ sticky : false ,
193197 hover : false ,
194198 condensed : false ,
195199 noDataIndication : null ,
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export default class SelectionCell extends Component {
7373 < BootstrapContext . Consumer >
7474 {
7575 ( { bootstrap4 } ) => (
76- < td onClick = { this . handleClick } { ...attrs } >
76+ < td data-row-selection onClick = { this . handleClick } { ...attrs } >
7777 {
7878 selectionRenderer ? selectionRenderer ( {
7979 mode : inputType ,
Original file line number Diff line number Diff line change 1+ @import " ./sticky" ;
Original file line number Diff line number Diff line change 1+ .react-bootstrap-table {
2+ .table-sticky {
3+ thead ,
4+ tbody {
5+ display : block ;
6+ width : 100% ;
7+
8+ tr {
9+ display : inline-flex ;
10+ width : 100% ;
11+
12+ th ,
13+ td {
14+ width : 100% ;
15+
16+ & [data-row-selection ] {
17+ width : 30px ;
18+ min-width : 30px ;
19+ }
20+ }
21+ }
22+ }
23+
24+ tbody {
25+ max-height : 400px ;
26+ overflow-y : auto ;
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ @import " partials/all" ;
2+
13.react-bootstrap-table {
24
35 table {
5557 content : " \2193 " ;
5658 }
5759
58- th [data-row-selection ] {
60+ th [data-row-selection ],
61+ td [data-row-selection ] {
5962 width : 30px ;
63+ min-width : 30px ;
6064 }
6165
6266 th > .selection-input-4 ,
You can’t perform that action at this time.
0 commit comments