-
Notifications
You must be signed in to change notification settings - Fork 781
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example on how to use floats in grid
it was initially unclear to me how to get floats to behave properly with sort + filter, so hopefully this helps someone
- Loading branch information
1 parent
d15518c
commit d2b7854
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
import React from 'react'; | ||
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table'; | ||
|
||
var products = []; | ||
|
||
function addProducts(quantity) { | ||
var startId = products.length; | ||
for (var i = 0; i < quantity; i++) { | ||
var id = startId + i; | ||
products.push({ | ||
id: id, | ||
name: "Item name " + id, | ||
price: (i*2 + Math.random()).toFixed(2), | ||
}); | ||
} | ||
} | ||
|
||
function formatFloat(cell, row) { | ||
console.log('formatFloat:', cell); | ||
return parseFloat(cell); | ||
} | ||
|
||
var sortFloat = function(l, r, order) { | ||
var left = parseFloat(l.price); | ||
var right = parseFloat(r.price); | ||
if (order === 'desc') { | ||
return right - left; | ||
} | ||
else { | ||
return left - right; | ||
} | ||
}; | ||
|
||
addProducts(5); | ||
|
||
export default class FloatFilter extends React.Component{ | ||
render(){ | ||
return ( | ||
<BootstrapTable data={products}> | ||
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn> | ||
<TableHeaderColumn dataField="name">Product Name</TableHeaderColumn> | ||
<TableHeaderColumn dataField="price" | ||
filter={{type: "NumberFilter", delay: 1000, numberComparators: ["=", ">", "<"]}} | ||
dataSort={true} | ||
dataFormat={formatFloat} | ||
filterFormatted={true} | ||
sortFunc={sortFloat}> | ||
Product Price | ||
</TableHeaderColumn> | ||
</BootstrapTable> | ||
); | ||
} | ||
}; |